0

我目前的理解是我必须在代码本身中分配坐标,而不是使用 interface-builder。有一个更好的方法吗?

目前我正在尝试处理登录视图。它在纵向模式下运行良好,但在横向模式下,很少有内容被隐藏。请建议如何处理。

谢谢

GuruPrasad R Gujjar。

4

1 回答 1

0

您可以通过以下两种方式之一来处理。第一个是您的建议并更改所有框架,第二个是仅拥有一个处于横向模式的单独视图并在旋转时将其切换出来。

对于这两种情况,您都需要实现这两种方法

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}
-(void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
    if (toInterfaceOrientation==UIInterfaceOrientationPortrait || toInterfaceOrientation== UIInterfaceOrientationPortraitUpsideDown) {
        //put the portrait orientation here
        self.usernameField.frame=CGRectMake(xPortraitLocation, yPortraitLocation, xWidth, yWidth);
        ...

    }
    else{
        //do the same thing with everything but for landscape mode
    }

对于单独的视图,您只需通过 self.view=self.lanscapeView 或 self.portraitView 将它们切换出来。

如果我要使用第一种方法,我有时喜欢在界面构建器中创建一个假视图,以便我可以将所有项目放在正确的位置并查看位置选项卡,这消除了分配数字的猜测和检查。

希望这可以帮助。

于 2011-04-29T16:29:48.003 回答