i've got a problem with iPhone SDK. I want create an imageView that user can touch and move and scale as he wish.
How can i do this?
Thank you
Look at UIGestureRecognizer : http://developer.apple.com/library/ios/#documentation/uikit/reference/UIGestureRecognizer_Class/Reference/Reference.html
Especially, UIPanGestureRecognizer and UIPinchGestureRecognizer
the easy way is to put it in a UIScrollView and enable the methods of the UIScrollViewDelegate that you wan't to use (scrool / zoom)
take a look at the apple sample project "PhotoScroller", you can find it in xCode help...
ciao, luca
for moving an object, you can CGAfflineTransformation to move from x axis to y axis.
u write up those code in Touch Delegates. also set the UIImage frame as CGRectZero.
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.50];
titl.transform=CGAffineTransformMakeTranslation(260, 0);
comment.transform=CGAffineTransformMakeTranslation(0, 100);
[UIView commitAnimations];
this is the code to move an object from one place to another. this might help you
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[UIView beginAnimations:nil context:NULL];
CGPoint touchPoint = [[touches anyObject] locationInView:[self window]];
float deltaX = touchPoint.x - lastUpdatedPoint.x;
float deltaY = touchPoint.y - lastUpdatedPoint.y;
float newCenterX = [[self layer] position].x + deltaX; float newCenterY = [[self layer] position].y + deltaY;
CGPoint center = CGPointMake(newCenterX, newCenterY);
[[self layer] setPosition:center];
lastUpdatedPoint = touchPoint;
[UIView commitAnimations];
}
BY CNSivakumar
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.