gpt4 book ai didi

ios - UIView transitionFromView 不在容器中设置动画

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:51:41 27 4
gpt4 key购买 nike

我正在使用 UIView transitionFromView 在两个 View 之间切换。我目前正在 UIView 子类中执行以下操作:

UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"img.png"]];

imgView.frame = CGRectMake(0, 0, 100, 100);

UIView *detailView = [[UIView alloc] initWithFrame:imgView.frame];
detailView.backgroundColor = [UIColor redColor];

detailView.frame = imgView.frame;

[self addSubview:imgView];

[UIView transitionFromView:imgView toView:detailView duration:1.0
options:UIViewAnimationOptionTransitionFlipFromLeft
completion:^(BOOL finished){

}
];

这按预期工作。转换按预期执行。问题是我需要在包含先前代码的 View 的 subview 中进行转换。所以,我将所有东西都放在一个容器中,并尝试为其制作动画:

UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"img.png"]];

imgView.frame = CGRectMake(0, 0, 100, 100);

UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
UIView *detailView = [[UIView alloc] initWithFrame:imgView.frame];
detailView.backgroundColor = [UIColor redColor];

detailView.frame = imgView.frame;

[container addSubview:imgView];

[self addSubview:container];

[UIView transitionFromView:imgView toView:detailView duration:1.0
options:UIViewAnimationOptionTransitionFlipFromLeft
completion:^(BOOL finished){

}
];

但在这种情况下,动画不会运行。相反,我只看到没有过渡的最终结果。谁能帮我弄清楚这两种情况有何不同?

此处描述了同样的问题,但我认为现有的“解决方案”不足以完全描述此行为。 Transition behavior using transitionFromView and transitionWithView

最佳答案

考虑将动画延迟到另一个运行循环,使用 dispatch_after 和 performSelector:withObject:afterDelay:

或者在添加 subview 后使用[CATransaction flush]

更多信息请访问 http://andrewmarinov.com/working-with-uiviews-transition-animations/

关于ios - UIView transitionFromView 不在容器中设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10395042/

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