我有这个方法,但我应该把这个方法放在哪里???
[[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];
}
答案 0 :(得分:1)
取决于你想要做什么。如果您只想更改视图的方向以匹配设备,则在viewController中实现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));
}
答案 1 :(得分:0)
请参阅this thread。