最近,我遇到了通过UIViews
分配动画IBOutlet
的问题。在代码中实例化视图然后设置动画时,一切正常。但如果它是在故事板中创建的并通过IBOutlet
分配,则无法使用动画。有什么我想念的吗?
@property (nonatomic, strong) IBOutlet UIView *foreground;
我正在使用动画块
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
NSLog(@"oldForegroundFrame %@, newForeGroundFrame: %@", NSStringFromCGRect(self.foreground.frame), NSStringFromCGRect(foregroundFrame));
self.foreground.frame = foregroundFrame;
NSLog(@"oldForegroundFrame %@, newForeGroundFrame: %@", NSStringFromCGRect(self.foreground.frame), NSStringFromCGRect(foregroundFrame));
} completion:^(BOOL finished) {
NSLog(@"oldForegroundFrame %@, newForeGroundFrame: %@", NSStringFromCGRect(self.foreground.frame), NSStringFromCGRect(foregroundFrame));
}];
NSLog打印输出显示分配后帧设置正确,但完成后将重置为原始位置。
oldForegroundFrame {{0,0},{320,133}},newForeGroundFrame:{{0,-45},{320,45}} oldForegroundFrame {{0,-45},{320,45}},newForeGroundFrame:{{0,-45},{320,45}} oldForegroundFrame {{0,0},{320,133}},newForeGroundFrame:{{0,-45},{320,45}}