简体   繁体   中英

IOS core animation for zoom in and zoom out

图片拍摄1影像拍摄2

I am working a pictureView which needs to be zoom in and zoom out on tap, I have searched for the proper zoom in and zoom out, but not found (I have tried to achieve same task with UIView but its not good), so i came to ask if any body can help ?

I have 4 images assembled in a tableview, 2 in a row. What i want is if user taps an image, it just zoom in and if he taps again it should zoom out. Following is the code sample i have tried so far

[UIView animateWithDuration:1.0f animations:^{
    img.frame = CGRectMake(0, 0, 300, 300);
    img.alpha = 1.0;
}];

but when ever i try to use that, instead of zooming in, it translates from one of the 4 diagonals :( I hope I have cleared this question as possible as I can.

Regards

  1. You need to add tap gesture recognizer for each UIImageView you are adding to the cells.
  2. You need to have hidden UIImageView to show when user taps the image. Here is what you do on tap: 2.1 Assign image to your hidden UIImageView , set its alpha to 0.0 and make it not hidden 2.2 Set proper frame to the hidden image view. 2.3 animate the reveal of the image like
 [UIView animateWithDuration:1.0f animations:^{ img.frame = CGRectMake(0, 0, 300, 300); img.alpha = 1.0; }]; 

2.4 add tap gesture recognizer to your hidden image view in order to dismiss it when user taps. 2.5 make reverse animation when user taps eg set alpha of displayed image view to 0.0 in uiview animation block.

I didn't provide the code for the whole thing assuming that you will learn and remember such things. Good Luck!

EDIT: don't forget to add hidden uiimageview to your view.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM