4
A
回答
3
假設您想從右側推view2來替換view1。
// Set up view2
view2.frame = view1.frame;
view2.center = CGPointMake(view1.center.x + CGRectGetWidth(view1.frame), view1.center.y);
[view1.superview addSubview: view2];
// Animate the push
[UIView beginAnimations: nil context: NULL];
[UIView setAnimationDelegate: self];
[UIView setAnimationDidStopSelector: @selector(pushAnimationDidStop:finished:context:)];
view2.center = view1.center;
view1.center = CGPointMake(view1.center.x - CGRectGetWidth(view1.frame), view1.center.y);
[UIView commitAnimations];
然後(任選地)實現此方法,從視圖層次結構中刪除廠景:
- (void) pushAnimationDidStop: (NSString *) animationID finished: (NSNumber *) finished context: (void *) context {
[view1 removeFromSuperview];
}
在你也可能希望釋放廠景,並根據設置其參照零,該動畫委託方法是否需要在轉換後保持它。
1
要從左動畫到右邊可以使用以下代碼塊
CATransition *transition = [CATransition animation];
transition.duration = 0.4;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
[self.view.window.layer addAnimation:transition forKey:nil];
[self presentViewController:YOUR_VIEWCONTROLLER animated:YES completion:nil];
1
另一種選擇是使用的動畫塊與碼的較小的線並且爲簡化:
下面是示例
CGRect viewLeftRect;//final frames for left view
CGRect viewRightRect;//final frames for right view
[UIView animateWithDuration:0.3f animations:^{
[viewLeft setFrame:viewLeftRect];
[viewRight setFrame:viewRightRect];
} completion:^(BOOL finished) {
//do what ever after completing animation
}];
0
您也可以從右動畫添加到左是這樣的:
scrAnimation.frame=CGRectMake(248, 175, 500, 414); //your view start position
[UIView animateWithDuration:0.5f
delay:0.0f
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
[scrAnimation setFrame:CGRectMake(0, 175, 500, 414)]; // last position
}
completion:nil];
相關問題
- 1. 如何使用Swift將自定義視圖右至左右左右移動
- 2. 圖像在android中從左到右從右至左滑動?
- 3. 在Cocoa Touch中爲圖像視圖設置動畫效果
- 4. CSS從左至右設置動畫Div寬度
- 5. 如何使用UIPageControl從左到右設置UIImageView的動畫效果?
- 6. 如何在將圖像從右向左移動時對imageview設置動畫
- 7. 如何在水平導航項下從左至右設置動畫邊框
- 8. 如何在iPhone應用程序中移動從左至右
- 9. 如何從左至右一個一個地動畫圖像android
- 10. D3折線圖動畫左至右
- 11. iOS「從左/右滑入」視圖動畫
- 12. 從左至右從右至左動畫從Android 2.1及以上版本
- 13. 在自定義視圖中爲Drawable設置動畫效果
- 14. 如何在Swift中將圖像視圖從左到右移動
- 15. 左右左動畫子視圖
- 16. 在圖像中設置動畫效果
- 17. Android如何從左至右滑動視圖
- 18. 從右至左設置MaskedTextBox值
- 19. 如何通過動畫從左至右移動屏幕?
- 20. 如何在iPhone上手動設置動畫效果?
- 21. 如何不在XAML中爲列表視圖設置動畫效果?
- 22. 如何從左至右只
- 23. 從右向左動畫UIView方向,iPhone
- 24. 使用緩動效果控制div的左/右動畫效果
- 25. 從左至右
- 26. 如何添加動畫效果左右滾動按鈕單擊?
- 27. Android從左至右滑動
- 28. 如何移動位圖併爲其設置動畫效果
- 29. Xcode:如何從左至右更改故事板加載動畫
- 30. 如何從左至右進行動畫製作?
謝謝你的回答。非常感謝....... – Pugal 2010-12-08 13:39:46