【问题标题】:Adding Two Listener For UIResponder为 UIResponder 添加两个监听器
【发布时间】:2023-03-26 10:44:01
【问题描述】:

我在 UIWindow 中添加了两个视图控制器作为子视图。现在的问题是视图之一得到视图旋转调用,但第二个是没有得到视图改变方向的调用。 现在我的问题是我们如何为 UIWindow 中添加的两个不同视图控制器获取更改方向调用。

【问题讨论】:

    标签: iphone objective-c ios uiresponder


    【解决方案1】:

    UIWindow 仅向其rootViewController 发送轮换消息。如果您希望其他视图控制器接收它们,您有两种选择:

    1. 编写代码让您的rootViewController 将旋转消息发送到另一个视图控制器。
    2. 实现视图控制器包含。观看来自WWDC 2011实施 UIViewController Containment 视频,了解如何执行此操作。

    【讨论】:

    • 我怎样才能以不编写代码来旋转视图的方式向视图控制器发送旋转调用(意味着自动调整大小属性有效)。我不想使用 CGAffineTransform 旋转视图
    • 如果您将视图设为UIWindow 的子视图,则必须使用CGAffineTransformUIWindow 为您设置rootViewController.view 的变换。如果您将其他子视图添加到窗口,您必须自己设置它们的变换。
    • 您可能会发现拥有窗口的单个子视图并让第二个视图控制器的视图成为该视图的子视图会更简单。
    • 其实第一个viewcontroller是Tab bar view controller,第二个是ads view controller(Mobclix)。现在,我在标签栏上方添加了广告,以便标签栏中的所有视图都可以看到它。当我在 UIWindow 中添加广告视图时,它不会随屏幕旋转,但全屏添加工作正常。当我在 tabbarcontroller 视图中添加广告时,它会旋转,但是当用户在横向模式下点击广告时。然后它会在视图之外显示全屏广告。
    • 感谢视频链接,-addChildViewController 将是我的解决方案。
    【解决方案2】:

    注册设备方向。

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(detectOrientation) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
    

    检查方法,

     if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) || 
            ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)) {
    
    
    }
    

    【讨论】:

      猜你喜欢
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      • 2018-05-03
      • 2012-11-30
      • 2018-08-30
      • 2020-06-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多