Проблема с UIButton в ориентации - PullRequest
0 голосов
/ 29 марта 2011

У меня есть одна кнопка, которая мне нужна, чтобы найти ее для каждой ориентации в разных местах.здесь у меня

- (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;
}

Сработало для первого поворота, при повторном повороте IPad кнопка снова переходит в другое место.например, в UIInterfaceOrientationPortrait кнопка не здесь (150.0f, 150.0f, 55.0f, 55.0f) Как я могу исправить эту проблему?Спасибо за помощь.

Ответы [ 2 ]

0 голосов
/ 29 марта 2011

Вы проверяете для UIInterfaceOrientationPortrait и UIInterfaceOrientationPortraitDown

Но правильное имя перечисления: UIInterfaceOrientationPortraitUpsideDown

См .: 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;
}
0 голосов
/ 29 марта 2011

Имя вашего параметра в методе interfaceOrientation, но вы проверяете orientation.Вы должны проверять 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;
    }
}
...