Problem with UIButton in orientation
I have one button that I need to locate it for each orientation in different location. here I have
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (interfaceOrientation== UIInterfaceOrientationPortrait || interfaceOrientation== UIInterfaceOrientationPortraitDown)
button.frame=CGRectMake(150.0f,150.0f,55.0f,55.0f);
else
button.frame=CGRectMake(100.0f,100.0f,55.0f,55.0f);
return YES;
}
It worked for the first rotation, when I rotate IPad again button goes to another location. for example in UIInterfaceOrientationPortrait the button goes not here (150.0f,150.0f,55.0f,55.0f) How can I fix this 开发者_运维知识库issue? Thanks for help.
The name of your parameter in the method is interfaceOrientation
but you are checking orientation
. You should be checking interfaceOrientation
:
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitDown) {
button.frame = CGRectMake(150.0f, 150.0f, 55.0f, 55.0f);
}
else {
button.frame = CGRectMake(100.0f, 100.0f, 55.0f, 55.0f);
return YES;
}
}
You are checking for UIInterfaceOrientationPortrait
and UIInterfaceOrientationPortraitDown
But the correct enumeration name is UIInterfaceOrientationPortraitUpsideDown
See: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIApplication_Class/Reference/Reference.html%23//apple_ref/c/tdef/UIInterfaceOrientation
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (interfaceOrientation== UIInterfaceOrientationPortrait || interfaceOrientation== UIInterfaceOrientationPortraitUpsideDown)
button.frame=CGRectMake(150.0f,150.0f,55.0f,55.0f);
else
button.frame=CGRectMake(100.0f,100.0f,55.0f,55.0f);
return YES;
}
精彩评论