我想用动画从我的超级UIView
中发送一个子视图,它工作正常,但是当我尝试在动画过程中更改大小时,我子视图中的任何UILabel
突然变得太小了。这是我代码的一部分
-(void)pushOutScreen:(UIViewController *)pop{
[UIView animateWithDuration:1
delay:0.0
options: UIViewAnimationTransitionFlipFromLeft
animations:^{
CGRect frame = pop.view.frame;
frame.size.height = frame.size.height /4;
frame.size.width = frame.size.width /4;
frame.origin.x = -500;
frame.origin.y = 318;
pop.view.frame = frame;
}
completion:^(BOOL finished){
NSLog(@"Done!");
}];
}
注意:我的子视图内的任何UIButton
或UIImage
动画效果很好,但我只有UILabel
问题。
UIView
动画不是执行此操作的好选择,而不是尝试CAKeyframeAnimation
。这是缩放UIView
的示例代码:
- (void) scaleView:(UIView *)popView {
CAKeyframeAnimation *animation = [CAKeyframeAnimation
animationWithKeyPath:@"transform"];
animation.delegate = self;
// CATransform3DMakeScale has 3 parameter (x,y,z)
CATransform3D scale1 = CATransform3DMakeScale(1.0, 1.0, 1);
CATransform3D scale2 = CATransform3DMakeScale(0.2, 0.2, 1);
NSArray *frameValues = [NSArray arrayWithObjects:
[NSValue valueWithCATransform3D:scale1],
[NSValue valueWithCATransform3D:scale2],
nil];
[animation setValues:frameValues];
NSArray *frameTimes = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.0],
[NSNumber numberWithFloat:1.0],
nil];
[animation setKeyTimes:frameTimes];
animation.fillMode = kCAFillModeForwards;
animation.removedOnCompletion = NO;
animation.duration = 1.0;
[popView.layer addAnimation:animation forKey:@"popup"];
}
可以在将UIView
添加为subView
后使用它,然后可以调用此方法作为缩放它。 要使用此方法推送子视图,您需要在动画完成后使用 removeFromSubView
。知道何时完成使用
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
[subView removeFromSuperview];
}
我希望它有用!