不同布局的旋转 - iOS 4
以下是我希望在应用程序中使用的两种布局。如果应用程序从纵向切换到横向时能够保留 UILabels、BOOL 和其他对象,那就太好了。因为按钮的位置不同,所以我不能只在自动旋转时让纵向视图自动调整大小。我还想使用 BOOL 和右上角的按钮来实现我自己的旋转锁。
我考虑过使用 -(void)orientationChanged:(NSNotification )notification 和 presentModalViewController 但这些并没有复制对象,似乎导致 弊大于利,而且似乎无法正常工作。
感谢您的帮助!
尝试的解决方案:
我将横向视图添加到 ViewController 中,在视图控制器。我将其链接到我在 ViewController 的 @interface 部分中添加的 UIView *landscapeView 下的文件所有者。我将 [self.view addSubview:landscapeView] 添加到 viewDidLoad 方法中。然后我添加了这段代码:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (orientationLock)
return NO;
else {
if (interfaceOrientation == UIInterfaceOrientationPortrait) {
[landscapeView setHidden:YES];
//[self.view setHidden:NO]; removed
} else {
//[self.view setHidden:YES]; removed
[landscapeView setHidden:NO];
}
return YES;
}
}
但这不是正确的解决方案。当我运行模拟器并旋转它时,屏幕未正确放置。
The following are the two layouts that I want have in my application. It would be nice if when the application switches from portrait to landscape that it keeps the UILabels, BOOLs, and other objects. Because the buttons are situated differently I cannot just have the portrait view autoresize on an auto rotate. I also want to implement my own rotation lock using a BOOL and the button on the top right.
I thought about using a -(void)orientationChanged:(NSNotification )notification with a presentModalViewController however these didn't copy over the objects and seemed to cause more harm then good and didn't appear to work properly.
Thanks for the help!
Attempted Solutions:
I added the landscape view to the ViewController, having both views in the view controller. I linked it up to File's Owner under the UIView *landscapeView that I added in the @interface section of the ViewController. I added [self.view addSubview:landscapeView] to the viewDidLoad method. Then I added this piece of code:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (orientationLock)
return NO;
else {
if (interfaceOrientation == UIInterfaceOrientationPortrait) {
[landscapeView setHidden:YES];
//[self.view setHidden:NO]; removed
} else {
//[self.view setHidden:YES]; removed
[landscapeView setHidden:NO];
}
return YES;
}
}
However this is not the correct solution. When I run the simulator and rotate it, the screen is not properly placed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当设备改变方向时,所有事情(您的实例变量值)保持不变。如果你只有一个 viewController 并且你在同一个视图中显示两个方向,那么你可以轻松管理这一点。我建议你在 nib 文件中创建两个 UIView,这样你就可以做你想做的所有事情。希望你明白我在说什么。如果你需要帮助,请告诉我。
这是修改后的代码
All things(your instance variables values) remains same when the device changes orientation. If you have only one viewController and you are showing both orieantation in the same then you can easily manage this. I suggest you to create two UIViews in the nib file that way you can do all the things you want.Hope you understand what I am talking about.Let me know if you need help.
Here is modified code