问题
I don't want to fade in and fade out like most common solution for the uiview animation. I would like to have the uiview resize to small until it disappear and comes back the same way. Another way to say it is having a camera pointing closely at the table with all the object in it (UIView) and camera backs up and the more it backs up the smaller the table gets. Which is why i titled which is mainly my app the whole uiview sinks into the water and floats back up. Hopefully i'll find a tutorial or someone's suggestion for the solution. everything resize/shrinks in the middle/center of the screen.
UPDATE*** i would like it to shrink in random position of the screen and appear from random position of the screen also. Also my subview from other class is viewdidload in mainView (View = [[View alloc] initWithFrame:CGRectMake(0, 40, 300, 300)];)
回答1:
Try this, where view
is the view you are messing with:
CGRect originalFrame = view.frame;
[UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationCurveEaseInOut animations:^{
CGRect frame = view.frame;
frame.origin = view.center;
frame.size = CGSizeMake( 0, 0 );
view.frame = frame;
} completion:^(BOOL finished) {
// Do something with the view
[UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationCurveEaseInOut animations:^{
view.frame = originalFrame;
} completion:^(BOOL finished) {
return;
}];
return;
}];
回答2:
You can have that effect by shrinking the frame to size (0,0) over the center of some point on the screen
// assume float cx,cy are defined as center coordinates of your animation (ie where your image shrinks and grows from)
// assume CGRect animFrame is defined as the starting coordinates of your animationView
// assume you have outlet to animationView
// to shrink
[UIView beginAnimations:@"WaterAnim" context:nil];
[UIView setAnimationDuration:0.33];
animationView.frame = CGRectMake(cx,cy, 0,0);
[UIView commitAnimations];
// to grow
[UIView beginAnimations:@"WaterAnim" context:nil];
[UIView setAnimationDuration:0.33];
animationView.frame = animationFrame;
[UIView commitAnimations];
来源:https://stackoverflow.com/questions/8175367/iphone-uiview-animation-resize-in-like-disappear-in-water-and-comes-back-floatin