iOS   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – UIView动画不起作用大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在myView显示器上进行setTingView并使用动画消失.
调用-showSetTingView
if(!self.setTingView):动画正常工作.
但是,如果(self.myView):setTingView消失WITHOUT动画.
如何修复它以使setTingView与动画一起消失?

@property (nonatomic,strong) UIView *myView;
@property (nonatomic,strong) UIView *setTingView;

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIBarButtonItem* setTingButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@SELEctor(showSetTingView)];
    self.navigationItem.rightBarButtonItem = setTingButton;
}

- (void)showSetTingView
{
    self.myView = [[UIView alloc]initWithFrame:CGRectMake(0,568,320,480)];
    self.myView.opaque = NO;
    self.myView.BACkgroundColor = [UIColor colorWithWhite:1.0f alpha:0.0f];
    [self.view addSubview:self.myView];

    if (!self.setTingView) {
        self.setTingView = [[UIView alloc]initWithFrame:CGRectMake(0,568)];
        self.setTingView.BACkgroundColor = [UIColor blackColor];
        [self.myView addSubview:self.setTingView];
        [UIView animateWithDuration:0.3f
                              delay:0.0f
                            options:UIViewAnimationOptionTransitionFlipFromBottom
                         animations:^{self.myView.frame = CGRectMake(0,60,480);}
                         completion:^(BOOL finished) {}
         ];
    } else if (self.myView){
        self.myView.frame = CGRectMake(0,480);
        [UIView animateWithDuration:0.3f
                              delay:0.0f
                            options:UIViewAnimationOptionCurveEaseIn
                         animations:^{self.myView.frame = CGRectMake(0,480);}
                         completion:^(BOOL finished) {}
         ];
        [self.setTingView removeFromSuperview];
        self.setTingView = nil;
        [self.myView removeFromSuperview];
    }
}

谢谢.

解决方法

您可以在动画开始之前取消设置视图.试试这个:

[UIView animateWithDuration:0.3f
                          delay:0.0f
                        options:UIViewAnimationOptionCurveEaseIn
                     animations:^{self.myView.frame = CGRectMake(0,480);}
                     completion:^(BOOL finished) {
                        [self.setTingView removeFromSuperview];
                        self.setTingView = nil;
                        [self.myView removeFromSuperview];
                     }
     ];

*另外:如果您使用的是自动布局,则需要执行以下选项之一:

A.在块之前设置myView的约束而不是框架,然后在块内部仅调用layoutIfNeeded:.

B.在动画块中设置transform属性.

大佬总结

以上是大佬教程为你收集整理的ios – UIView动画不起作用全部内容,希望文章能够帮你解决ios – UIView动画不起作用所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。