gpt4 book ai didi

ios - 如何添加带有翻转动画的 subview ?

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

如果您创建一个全新的单 View 应用程序并将此代码放在按钮后面:

UIView *blah = [[UIView alloc] initWithFrame:CGRectMake(0,0,100,100)];
blah.backgroundColor = [UIColor grayColor];
[UIView transitionWithView:blah duration:1
options:UIViewAnimationOptionTransitionFlipFromRight
animations:^{
[self.view addSubview:blah];
}
completion:^(BOOL finished){

}];

subview 立即添加,没有动画。如果您先添加 subview 然后尝试为其设置动画...您会遇到同样的问题。

    UIView *blah = [[UIView alloc] initWithFrame:CGRectMake(0,0,100,100)];
[self.view addSubview:blah];
[UIView transitionWithView:blah duration:1
options:UIViewAnimationOptionTransitionFlipFromRight
animations:^{
blah.backgroundColor = [UIColor grayColor];
}
completion:^(BOOL finished){

}];

到底如何在添加 subview 时或添加后立即为 subview 设置翻转动画?

最佳答案

你通常需要有约束动画的容器已经就位:

- (void)viewDidLoad
{
[super viewDidLoad];

CGRect frame = CGRectMake(0, 0, 100, 100);

_container = [[UIView alloc] initWithFrame:frame];
_container.backgroundColor = [UIColor lightGrayColor];
[self.view addSubview:_container];
}

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];

UIView *subview = [[UIView alloc] initWithFrame:_container.bounds];
subview.backgroundColor = [UIColor darkGrayColor];

[UIView transitionWithView:_container
duration:1.0
options:UIViewAnimationOptionTransitionFlipFromRight
animations:^{
[_container addSubview:subview];
}
completion:NULL];
}

关于ios - 如何添加带有翻转动画的 subview ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16224969/

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