(iOS 5.1,XCode 4.4) 在我正在開發的項目中,我有兩個控制器,它們都設置相同UIView的框架屬性(設置大小和位置,分別)在時間上重疊的單獨動畫塊中(第二個動畫塊在第一個動畫塊在第一個動畫塊完成之前開始)。這似乎會導致UIView位置出現奇怪的跳躍(無生氣的變化)。在重疊動畫塊中設置UIView的框架屬性會導致跳轉
最小的例子重現(在視圖控制器中放置一個新的單視圖項目(iphone),並將一些按鈕連接到操作方法)。
@interface ViewController()
@property (nonatomic, strong) UIView *viewA;
@end
@implementation ViewController
- (IBAction)buttonPressed
{
// Animate
[UIView animateWithDuration:5 animations:^{
self.viewA.frame = CGRectMake(0, self.viewA.frame.origin.y, 320, 200);
}];
[UIView animateWithDuration:5 animations:^{
self.viewA.frame = CGRectMake(0, 200, 320, self.viewA.frame.size.height);
}];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.viewA = [[UIView alloc] init];
self.viewA.backgroundColor = [UIColor orangeColor];
self.viewA.frame = CGRectMake(0, 100, 320, 100);
[self.view addSubview:self.viewA];
}
@end
在按下按鈕,你會看到視圖跳約50像素(一半是中移動的距離)。
如果有人知道這是爲什麼發生和/或如何解決這個問題,我很樂意聽取您的意見。謝謝你在前進,
帕特里克
不知道你必須明確指定(默認情況下CALayer上的隱式動畫有這個)。非常感謝! – 2012-07-31 06:47:36