I'm trying to set another position for a UIButton when I change the orientation of my IPhone and I had the idea to implement it inside BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation. Is this the right way to implement or is there any error on my code? It's not printing these logs.
Code:
- (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;
}
Regards!
Your code too should work but try putting following code. Change is from UIDeviceOrientation to UIInterfaceOrientation
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight))
{
NSLog(@"Csantos shouldAutorotateToInterfaceOrientation: left or right");
[adButton setFrame:CGRectMake(100, 700, 768, 90)];
}
if ((interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))
{
NSLog(@"Csantos shouldAutorotateToInterfaceOrientation: Portrait or UpsideDown portrait");
[adButton setFrame:CGRectMake(0, 0, 768, 90)];
}
return YES;
}
shouldAutorotateToInterfaceOrientation simply specifies what rotations are supported by a UIViewController - nothing more.
You may consider modifying willRotateToInterfaceOrientation which is called just before a rotation is about to begin - to hide background views or other objects, for example.
Then, override didRotateFromInterfaceOrientation which is called after a rotation has just finished - I think this one will be the most important for your setFrame: code.
I don't undestand, the adButton setFrame works correctly or not and this viewcontroller is root or you have another one. Can't it be that root controller shouldAutorotateToInterfaceOrientation return NO for any orientation?
精彩评论