视图无缘无故移动

发布于 2024-11-30 14:01:38 字数 1235 浏览 0 评论 0原文

有点奇怪。因此,我让我的 iPhone 应用程序在各个屏幕之间完美导航,并决定在所有页面之间添加动画。添加后,动画本身都工作正常,但是当我从主页移开时,视图似乎在窗口内向上移动了一小段距离。之后,无论我移动到哪个页面,视图都会稍微向上移动。直到我导航到自动旋转以适应视频的页面之一。在此页面上时,视图非常适合屏幕,当我导航离开时,视图会翻转回纵向,然后视图再次非常适合所有其他屏幕,没有移动。所有这一切都发生在我添加屏幕动画代码之后,但我完全不明白为什么这会影响这一点,除非我不小心更改了其他内容。

以下是我放入动画中使用的代码:

WhatIsCTTView *whatIsCTTView = [[WhatIsCTTView alloc] initWithNibName:@"WhatIsCTTView" bundle:nil];
UIView *currentView = self.view;
UIView *theWindow = [currentView superview];
UIView *newView = whatIsCTTView.view; 
[currentView removeFromSuperview];
[theWindow addSubview:newView];
CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[theWindow layer] addAnimation:animation forKey:@"SwitchToCTTView"];

任何帮助将不胜感激,

谢谢,

马特

编辑:

我找到了如何解决这个问题,只需添加行

“newView.frame = CGRectMake(0, 20, 320, 460);"

将新的子视图添加到屏幕后,确保其放置在正确的位置。请参阅这个问题(http://stackoverflow.com/questions/3952483/iphone-addsubview-show-view-too-high-up-how-do-i-move-to-down)以获取答案。

马特

Bit of a strange one. So I had my iPhone app navigating between various screens perfectly fine and the decided to add animations between all the pages. Once added in, the animations themselves all worked fine, but as soon as I move from the home page, the view seems to shift up inside the window a small distance. After that, whichever page I move to, the view stays shifted slightly up. That is until I navigate to one of my pages which auto rotates to accommodate for videos. When on this page, the view fits the screen fine, and when I navigate off, the view flips back to portrait and the view is then perfectly fine for all of the other screens again, no shifting. All of this happened after I added the animation code for the screens but I can't see why that would have affected this at all unless I accidentally changed something else.

The following is the code I have put in to use with animations:

WhatIsCTTView *whatIsCTTView = [[WhatIsCTTView alloc] initWithNibName:@"WhatIsCTTView" bundle:nil];
UIView *currentView = self.view;
UIView *theWindow = [currentView superview];
UIView *newView = whatIsCTTView.view; 
[currentView removeFromSuperview];
[theWindow addSubview:newView];
CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[theWindow layer] addAnimation:animation forKey:@"SwitchToCTTView"];

Any help would be greatly appreciated,

Thanks,

Matt

EDIT:

I found out how to fix this problem, just add the line

"newView.frame = CGRectMake(0, 20, 320, 460);"

after you add a new subview to the screen to make sure it is placed in the right position. See this SO question (http://stackoverflow.com/questions/3952483/iphone-addsubview-show-view-too-high-up-how-do-i-move-to-down) for where I got my answer.

Matt

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文