gpt4 book ai didi

objective-c - 当父 UIView 动画时,UILabel 大小突然改变

转载 作者:搜寻专家 更新时间:2023-10-30 20:21:04 24 4
gpt4 key购买 nike

我想从我的 super UIView 中发送一个带动画的 subview ,它工作正常但是当我试图在动画期间更改大小时我在任何 UILabel我的 subview 突然变得太小了。这是我的部分代码

-(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!");
}];
}

注意:我的 subview 中的任何 UIButtonUIImage 动画都很好,但我只有 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 之后使用它,然后您可以调用此方法来缩放它。要使用此方法推出 subview ,您需要在动画完成后使用 removeFromSubView。因为知道当它完成使用时

-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
[subView removeFromSuperview];
}

希望有用!

关于objective-c - 当父 UIView 动画时,UILabel 大小突然改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10967067/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com