Im a beginner programmer with Xcode 5 and was attempting to write code to allow a user to move a image with input from the users touch.
So far, I believe that my code is correct but i believe I'm missing something as the UIImage refuses move. Although when attempt to test it with NSLog I don't get a response which shows it working. My guess it that I have to make a custom class for the image and if so would I do this and how would I link it.
For example
@implementation StartPage
- (IBAction)HandlePan:(UIGestureRecognizer *)sender; {
NSLog(@"panning"); //Testing to check if the image moves when touched by user.
CGPoint NetTranslation ;
CGPoint Translation =
[(UIPanGestureRecognizer *) sender translationInView: _Imageview ];
sender.view.transform=CGAffineTransformMakeTranslation (
NetTranslation.x += Translation.x,
NetTranslation.y += Translation.y);
enter code here
if(sender.state == UIGestureRecognizerStateEnded)
{
NetTranslation.x += Translation.x;
NetTranslation.y += Translation.y;
}
}
If your HandlePan
method is not called check that your _Imageview has user interactions enabled:
_Imageview.userInteractionEnabled = YES