gpt4 book ai didi

ios - UIView 动画不起作用

转载 作者:可可西里 更新时间:2023-11-01 05:12:38 26 4
gpt4 key购买 nike

我想让 myView 上的 settingView 显示并随着动画消失。
我调用 -showSettingView
if (!self.settingView) :动画正常工作。
但是,else if (self.myView) : settingView 在没有动画的情况下消失。
如何修复它,使 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, 0, 320, 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, 320, 480);}
completion:^(BOOL finished) {}
];
} else if (self.myView){
self.myView.frame = CGRectMake(0, 60, 320, 480);
[UIView animateWithDuration:0.3f
delay:0.0f
options:UIViewAnimationOptionCurveEaseIn
animations:^{self.myView.frame = CGRectMake(0, 568, 320, 480);}
completion:^(BOOL finished) {}
];
[self.settingView removeFromSuperview];
self.settingView = nil;
[self.myView removeFromSuperview];
}
}

谢谢。

最佳答案

您在动画开始之前释放设置 View 。试试这个:

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

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

一个。在 block 之前设置 myView 的约束而不是框架,然后在 block 内调用 only layoutIfNeeded:

B.在动画 block 中设置 transform 属性。

关于ios - UIView 动画不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23043842/

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