【问题标题】:Which method determines the rotation of device from Portrait to Landscape mode哪种方法确定设备从纵向模式到横向模式的旋转
【发布时间】:2009-09-19 05:46:22
【问题描述】:

我有这个方法但是我应该把这个方法放在哪里???

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

// This method is called by NSNotificationCenter when the device is rotated.
-(void) receivedRotate: (NSNotification*) notification
{
    UIDeviceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation];
    if(interfaceOrientation != UIDeviceOrientationUnknown)
        [self deviceInterfaceOrientationChanged:interfaceOrientation];
}

【问题讨论】:

    标签: iphone


    【解决方案1】:

    取决于你想要做什么。如果您只想更改视图的方向以匹配设备,则在您的视图控制器中实现 willRotateToInterface 和 shouldAutorotateToInterfaceOrientation。这比什么都简单。在 shouldAutorotateToInterfaceOrientation 中,您只需为您愿意接受的每个方向返回一个 YES。下面是例程的样子:

    // Override to allow orientations other than the default portrait orientation.
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        // Return YES for supported orientations
        return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || 
                (interfaceOrientation == UIInterfaceOrientationLandscapeRight));
    }
    

    【讨论】:

      【解决方案2】:

      this thread

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-06-12
        • 1970-01-01
        相关资源
        最近更新 更多