我正在构建一个具有多个由 RootViewController 控制的 UIViewController 的应用程序。目前,在 plist 中,应用程序默认为 LandscapeRight。
假设我有以下文件可以加载到 RootViewController 中:
- IntroView (仅横向右)
- LandscapeView (仅横向右)
- PortraitView (仅纵向)
我还在 RootViewController 的 shouldAutorotateToInterfaceOrientation 中添加了以下内容:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if ([currentClass class] == PortraitView.class) {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
} else {
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
}
所以一切都很好,直到我加载在 PortraitView 和 viewWillAppear 中,我添加以下内容(类似于 此线程
if (self.interfaceOrientation == UIInterfaceOrientationPortrait) { //UIInterfaceOrientationLandscapeRight) {
self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90));
self.view.bounds = CGRectMake(0.0, 0.0, 320, 480);
self.view.center = CGPointMake(240.0f, 160.0f);
}
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
这会在 PortraitView 中正确加载,但现在我的问题是,在我的 PortraitView 中,我有 2 个子视图,我想在它们之间翻转,但因为我旋转了我的视图 UIViewAnimationTransitionFlipFromLeft 实际上使它从上到下翻转,而不是从左到右翻转
。当我尝试使用 shouldAutorotateToInterfaceOrientation 并将其设置为仅纵向时,它会旋转我的视图,因此它不再正确。
希望这是有道理的!一整天都在看这个问题。
谢谢!
I am building an application with multiple UIViewControllers controlled by a RootViewController. Currently in the plist the application defaults to LandscapeRight.
Lets say I have the following files that can be loaded into the RootViewController:
- IntroView (Landscape Right ONLY)
- LandscapeView (Landscape Right ONLY)
- PortraitView (Portrait ONLY)
I also added into the RootViewController's shouldAutorotateToInterfaceOrientation the following:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if ([currentClass class] == PortraitView.class) {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
} else {
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
}
so all is well until I load in the PortraitView and in the viewWillAppear i add the following (similar to this thread
if (self.interfaceOrientation == UIInterfaceOrientationPortrait) { //UIInterfaceOrientationLandscapeRight) {
self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90));
self.view.bounds = CGRectMake(0.0, 0.0, 320, 480);
self.view.center = CGPointMake(240.0f, 160.0f);
}
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
This yields a properly loaded in PortraitView but now my issue is that within my PortraitView I have 2 subviews that I would like to flip between, but because I rotated my view UIViewAnimationTransitionFlipFromLeft actually makes it flip top to bottom instead of left to right. I cannot for the life of me figure out how to tell PortraitView that its in Portrait.
When I check [[UIDevice currentDevice] orientation]; it tells me its in Landscape. When I attempt to use shouldAutorotateToInterfaceOrientation and set it to Portrait only it will then rotate my view so it is no longer correct.
Hopefully this makes sense! Been looking at this issue all day.
Thanks!
发布评论
评论(1)
我遇到的情况略有不同;横向模式下的 UIViewController 子类,从上到下而不是从左到右交换。
对我有用的修复是将所有视图添加到单个“内部”视图,然后翻转它,而不是 UIViewController 的正常视图。
其中
[self insideView]
是[self view]
的唯一子视图,所有子视图都在其中。I ran into this slightly differently; a
UIViewController
subclass in landscape mode that swapped top-to-bottom instead of left-to-right.The fix that worked for me was to add all my views to a single “inner” view and then flip that instead of the
UIViewController
’s normalview
.Where
[self innerView]
is the sole child of[self view]
, and all the subviews are inside of it.