[英]View Orientation changes
Update: I found why it was loading the same view the whole time.更新:我发现为什么它一直在加载相同的视图。 I now fixed that.
我现在解决了这个问题。 It was a typo
这是一个错字
ControllerForSplitViews.m ControllerForSplitViews.m
- (id)init
{
self = [super initWithNibName:@"ControllerForSplitViews" bundle:nil];
if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation)){
self.view = landscapeView;
}
if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation)){
self.view = portraintView;
}
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
return self;
}
This works.这行得通。
Now the problem.现在的问题。 When the view is loaded and running I change the orientation and load a different view from the same nib file, Fixed: but as soon as I do this the other UI elements disappears and only the ui elements of my landscape view is kept and when I rotate the device again it doesn't load my portrait view again?
当视图加载并运行时,我更改方向并从同一个 nib 文件加载不同的视图,已修复:但是一旦我这样做,其他 UI 元素就会消失,只有我的横向视图的 ui 元素被保留,当我再次旋转设备它不会再次加载我的纵向视图? Any suggestions why this might happen?
有什么建议为什么会发生这种情况?
-(void) orientationChanged:(id)object
{
if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation))
{
self.view = portraintView;
}
if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
{
self.view = landscapeView;
}
}
New Problem, each time I change the orientation it loads the opposite orientation's view新问题,每次我改变方向时,它都会加载相反方向的视图
Thanks谢谢
I am adding this here as well for incase someone ever reads this, they might want to check out this post here where a simular scenario was discussed我也在此处添加此内容,以防有人读过此内容,他们可能想在此处查看此帖子,其中讨论了一个类似的场景
Two views Multiple UIPickerViews Single outlet 两个视图 多个 UIPickerViews 单个出口
Ok so I found a fix that works, but I have no idea why my original code didn't work what I did was:好的,所以我找到了一个有效的修复程序,但我不知道为什么我的原始代码不起作用我所做的是:
Remove:消除:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
Remove:消除:
-(void) orientationChanged:(id)object
{
if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation))
{
self.view = portraintView;
}
if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
{
self.view = landscapeView;
}
}
Change:改变:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
(interfaceOrientation == UIInterfaceOrientationLandscapeRight))){
self.view = landscapeView;
}else if(((interfaceOrientation == UIInterfaceOrientationPortrait) ||
(interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))){
self.view = portraintView;
}
return YES;
}
And now it works perfectly现在它完美运行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.