当我改变我的iPhone的方向并且我有想在BOOL中实现它时,我正试图为UIButton设置另一个位置)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation . 这是正确的实现方式还是我的代码有错误?它不打印这些日志 .
码:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if ((interfaceOrientation == UIDeviceOrientationLandscapeLeft) ||
(interfaceOrientation == UIDeviceOrientationLandscapeRight))
{
NSLog(@"Csantos shouldAutorotateToInterfaceOrientation: left or right");
[adButton setFrame:CGRectMake(100, 700, 768, 90)];
}
if ((interfaceOrientation == UIDeviceOrientationPortrait) ||
(interfaceOrientation == UIDeviceOrientationPortraitUpsideDown))
{
NSLog(@"Csantos shouldAutorotateToInterfaceOrientation: Portrait or UpsideDown portrait");
[adButton setFrame:CGRectMake(0, 0, 768, 90)];
}
return YES;
}
问候!
3 回答
您的代码也应该可以工作,但尝试下面的代码 . 变更是从 UIDeviceOrientation 到 UIInterfaceOrientation
shouldAutorotateToInterfaceOrientation只是指定UIViewController支持的旋转 - 仅此而已 .
您可以考虑修改在旋转即将开始之前调用的willRotateToInterfaceOrientation - 例如,隐藏背景视图或其他对象 .
然后,覆盖在旋转刚完成后调用的didRotateFromInterfaceOrientation - 我认为这对于你的setFrame来说是最重要的:代码 .
我没有看不到,adButton setFrame工作正常与否,这个viewcontroller是root或你有另一个 . 难道不能是root控制器应该是否为任何方向返回NO?