How to move resizableUIView from its corner in iOS?

I want to drag resizable UIView from its corner? Like on desktop we Click the mouse button and hold on click and drag the mouse then a transparent view is visible like this.

I want this in my Project in iPhone. I want when the user touch and drag the finger one resizable transparent view will visible.

I have done so far on click on button the view is visible and that is resizable also. But it is not my solution, I want on touch on any iphone screen the resizable UIView will come.

Any Idea and suggestions would be highly welcome.

This is my code what I have done so far:

- (void)viewDidLoad
{


tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
tap.numberOfTapsRequired = 1;
[imageVw addGestureRecognizer:tap];
tap.delegate=self;
pan=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panAction:)];
[pan setMinimumNumberOfTouches:1];
[pan setMaximumNumberOfTouches:2];
[pan setDelegate:self];
count=0;
//    [pan minimumNumberOfTouches:1];
//    [pan maximumNumberOfTouches:2];
[imageVw addGestureRecognizer:pan];
}



-(void)handleTap:(UIPanGestureRecognizer *)gestureRecognizer
{

userResizableView = [[SPUserResizableView alloc] init];
userResizableView.frame = CGRectMake(x,y,w,h);
//UIView *content_View = [[UIView alloc] initWithFrame:userResizableView.bounds];
//[content_View setBackgroundColor:[UIColor whiteColor]];
imageVw1 = [[UIImageView alloc]initWithFrame:userResizableView.bounds];
//imageVw1.image = [UIImage imageNamed:@"redacted2.jpg"];
imageVw1.backgroundColor = [UIColor blackColor];
imageVw1.userInteractionEnabled=YES;
imageVw1.autoresizesSubviews = YES;
imageVw1.alpha = 0.13;  // for opacity
userResizableView.contentView = imageVw1;
//[content_View addSubview:imageVw1];

//userResizableView.contentView = content_View;
userResizableView.delegate = self;
[userResizableView showEditingHandles];
currentlyEditingView = userResizableView;
lastEditedView = userResizableView;

// [self.view addSubview:userResizableView];
// [imageVw addSubview: dview];
[self.view addSubview: userResizableView];
[userResizableView release];

}

- (void)userResizableViewDidBeginEditing:(SPUserResizableView *)userResizableView1 {

 width  =   userResizableView.frame.size.width;
 height  =   userResizableView.frame.size.height;
 width1 = width;
 height1 = height;
 width = width + width;
 height = height + height;
[currentlyEditingView hideEditingHandles];
currentlyEditingView = userResizableView1;


}

- (void)userResizableViewDidEndEditing:(SPUserResizableView *)userResizableView1 {

lastEditedView = userResizableView1;
x1 = x;
y1 = y;
x =  userResizableView.frame.origin.x;
y = userResizableView.frame.origin.y;

}

Answers


First you have to declare two global variables

CGPoint startPoint;
BOOL _shouldResize;

Then you have to override two touch event methods in your view as given

1.TouchesBegan

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

CGPoint touchPoint = [[touches anyObject] locationInView:[self superview]];

/*

 Here you have to check user tap to the corner of your view by using the method
 CGRectContainsPoint(CGRect rect, touchPoint);

 Here the parameter rect should be the corner of your view

 if(!CGRectContainsPoint(CGRect rect, touchPoint)) { // Here user did not tap in your specific rect. so no need of resizing

    _shouldResize = NO;
    return;
 }

 */

_shouldResize = YES;

startPoint = touchPoint;

}

2.TouchesMoved

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

if(!_shouldResize)
    return;

CGPoint touchPoint = [[touches anyObject] locationInView:[self superview]];

CGFloat displacementX = touchPoint.x - startPoint.x;
CGFloat displacementY = touchPoint.y - startPoint.y;

startPoint.x = touchPoint.x;
startPoint.y = touchPoint.y;

CGRect frame = [self frame];
frame.size.width += displacementX;
frame.size.height += displacementY;

[self setFrame:frame];

}

Hope this will help you :)


Need Your Help

Creating a window from a new thread in WPF app with no main window

c# wpf user-interface systray windowless

I'm working on a WPF application that has no main window (it runs in the notification area using code from http://www.codeproject.com/KB/WPF/wpf_notifyicon.aspx).

Translating Ruby code to Java

java ruby rating bayesian

I have never used ruby but need to translate this code to java.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.