2011-11-17 49 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