lantianyiming 2013-08-26 06:38 采纳率: 0%
浏览 1078

竖屏模式自定义segue

需要创建自定义segue,实现功能是不管手机如何旋转,下一个视图都锁定为竖屏模式。我已经创建了UIStoryBoardSegue 文件,但是我现在横屏到竖屏的转换有问题:

-(void) perform

{
        self.appDelegate = [[UIApplication sharedApplication] delegate];
        UIViewController *source = (UIViewController *) self.sourceViewController;
        UIViewController *destination = (UIViewController *) self.destinationViewController;



    }
  • 写回答

1条回答 默认 最新

  • ChatGPTᴼᴾᴱᴺᴬᴵ 2023-01-13 20:03
    关注

    为了锁定竖屏模式,你可以在 perform 方法中设置 destination 视图控制器的屏幕方向为竖屏,并在转场动画完成后将其还原。


    你可以使用以下代码来实现这一点:

    - (void) perform
    {
            UIViewController *destination = (UIViewController *) self.destinationViewController;
            UIInterfaceOrientation currentOrientation = [UIApplication sharedApplication].statusBarOrientation;
            if (currentOrientation == UIInterfaceOrientationLandscapeLeft || currentOrientation == UIInterfaceOrientationLandscapeRight) {
                [destination setValue:@(UIInterfaceOrientationPortrait) forKey:@"orientation"];
            }
            [self.sourceViewController presentViewController:destination animated:YES completion:nil];
    }
    

    需要注意的是,上面的代码只能在 iOS 13 及以下版本上使用。在 iOS 13 及以上版本中,您需要使用新的屏幕方向API来设置目标控制器的屏幕方向。


    另外,您可能需要在目标视图控制器中重写 shouldAutorotate 方法并返回 NO,以确保它不会自动旋转。

    评论

报告相同问题?

悬赏问题

  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?