2011-11-17 52 views
0

我不想淡入和淡出像uiview动画的大多数常见解决方案。我希望将uiview的大小调整到很小,直到它消失并以相同的方式返回。另一种说法是,摄像机将桌子上的所有物体(UIView)和摄像机备份在桌子上,桌子越小,桌子越小。这就是为什么我标题是哪个主要是我的应用程序,整个uiview沉入水中并浮起来。希望我会找到解决方案的教程或某人的建议。一切都在屏幕的中间/中心缩放/缩小。iphone UIview动画调整大小就像在水中消失,浮回来

更新*** 我希望它缩小在屏幕的随机位置,并从屏幕的随机位置也出现。 另外,从其他类我的子视图中MAINVIEW 被viewDidLoad中(查看= [[查看的alloc] initWithFrame:方法CGRectMake(0,40,300,300)];)

回答

2

试试这个,在这里view是要搞乱视图的中心:我从苹果文档阅读

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; 
}]; 
+0

感谢您的时间。我已经尝试过了,它将子视图(View = [[View alloc] initWithFrame:CGRectMake(0,40,300,300)];)从其他类向右下移回到原始框架。它的接近,但我希望它收缩后回来,而不是把它移到右下和后面。我还更新了随机位置部分的帖子。 – merrill

+0

好的,尝试在视图上将'clipsToBounds'设置为YES,尽管这可能会导致奇怪的效果。如果确实如此,请告诉我,我有另一个准备好的答案。 – aopsfan

+0

,效果好得多,但没有收缩。它正在右下方消失(在黑色公园的底部和右侧),你可以看到它消失的两侧。也希望消失在随机位置,并出现随机位置=) – merrill

0

可以具有由帧尺寸缩小该效果(0,0)在某一时刻的屏幕

// 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]; 
+0

了' beginAnimations:''commitAnimations'方法不再被支持。现在鼓励像[[UIView animateWithDuration:动画:]]这样的方法。 – aopsfan