iPhone:仅具有横向和纵向视图的应用程序

发布于 2024-10-03 02:24:05 字数 1610 浏览 3 评论 0 原文

我正在构建一个具有多个由 RootViewController 控制的 UIViewController 的应用程序。目前,在 plist 中,应用程序默认为 LandscapeRight。

假设我有以下文件可以加载到 RootViewController 中:

  1. IntroView (仅横向右)
  2. LandscapeView (仅横向右)
  3. 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:

  1. IntroView (Landscape Right ONLY)
  2. LandscapeView (Landscape Right ONLY)
  3. 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!

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

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

发布评论

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

评论(1

十雾 2024-10-10 02:24:05

我遇到的情况略有不同;横向模式下的 UIViewController 子类,从上到下而不是从左到右交换。

对我有用的修复是将所有视图添加到单个“内部”视图,然后翻转它,而不是 UIViewController 的正常视图。

    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
                           forView:[self innerView]
                             cache:YES];

其中 [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 normal view.

    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
                           forView:[self innerView]
                             cache:YES];

Where [self innerView] is the sole child of [self view], and all the subviews are inside of it.

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