更改UIBarButtonItem的位置

时间:2012-08-08 12:37:49

标签: objective-c ios xcode uibarbuttonitem

我正在开发一个iPad项目,我想处理纵向和横向视图两种模式。

当我进入横向模式时,UIBarButtonItem不会改变位置。是否有方法移动此按钮并将其放在栏的右侧?

肖像:

enter image description here

风景:

enter image description here

谢谢。

2 个答案:

答案 0 :(得分:1)

我认为目前的位置设置如下:

ss

在此设置下,横向模式采用左边距的长度。因此,您必须设置右边距的长度,并将按钮放在导航栏的右端。

您最好将设置设置如下:

ss

您可以通过尺寸检查员编辑这些设置(请自行查看)。

我有这个建议对你有帮助。

答案 1 :(得分:1)

解决了这样的问题:

在我写的willAnimateRotationToInterfaceOrientation方法中:

if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight){
        //Change the position of the profil button
        [self changeProfilButtonOrientation];   
    }else if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown || toInterfaceOrientation == UIInterfaceOrientationPortrait){

    }

我的changeProfilButtonOrientation方法

-(void) changeProfilButtonOrientation{
    UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    [self.toolBar setItems:[NSArray arrayWithObjects:flexibleSpace,profilButton, nil]];
}

它有效: - )

相关问题