切换视图时第二次视图不显示?

发布于 2025-01-01 18:42:51 字数 699 浏览 5 评论 0原文

在我的应用程序中,当我使用 UIView 动画切换动画视图时,第一次切换视图时效果很好,因为视图正确滑动到位并且一切正常。但是,如果我切换回原始视图,然后返回新视图,它不会显示任何内容,视图是黑色的,但我知道我的方法正在被调用。

我的代码如下,但有人看到有什么问题吗?

-(void)changeView2ToView3 {
    [view2.view.superview addSubview:view3.view];
    [view3.view setFrame:CGRectMake(0, kHeight, kWidth, kHeight)];
    [UIView animateWithDuration:0.75 
                     animations:^{
                         [view3.view setFrame:CGRectMake(0, 0, kWidth, kHeight)];  
                     }
                     completion:^(BOOL finished){
                         [view2.view removeFromSuperview];
                     }];
}

kHeight 和 kWidth 是屏幕的高度和宽度,它们绝不是 0 或 nil。

谢谢!

In my app when I am switching views with an animation using UIView animations, it works fine the first time when I switch views because the view slides properly into place and everything works. But if I switch back to my original view and then go BACK to the new view, it does not show anything, the view is black but I know my method is getting called.

My code is below, but does anyone see anything that is wrong?

-(void)changeView2ToView3 {
    [view2.view.superview addSubview:view3.view];
    [view3.view setFrame:CGRectMake(0, kHeight, kWidth, kHeight)];
    [UIView animateWithDuration:0.75 
                     animations:^{
                         [view3.view setFrame:CGRectMake(0, 0, kWidth, kHeight)];  
                     }
                     completion:^(BOOL finished){
                         [view2.view removeFromSuperview];
                     }];
}

kHeight and kWidth are the height and width of the screen and they are never 0 or nil.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝眸 2025-01-08 18:42:51

第一次之后,view2.view 的 superview 必须为零。所以你必须设置一个变量来保存超级视图。

[view2.view removeFromSuperview];
// now view2.view.superview == nil;

After the first time, view2.view's superview must be nil. So you have to set a variable for saving the superview.

[view2.view removeFromSuperview];
// now view2.view.superview == nil;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文