首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIToolbar和CGRectMake

UIToolbar和CGRectMake
EN

Stack Overflow用户
提问于 2013-06-13 05:33:13
回答 2查看 166关注 0票数 1

我在一个ViewControler中有2个UIToolbar。

我需要改变他们轮换的位置。

我增加了2个插座

代码语言:javascript
复制
@property (nonatomic, retain) IBOutlet UIToolbar *toolbar1;
@property (nonatomic, retain) IBOutlet UIToolbar *toolbar2;

立即在视图控制器的IB中连接它们。我使用以下代码

代码语言:javascript
复制
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
        toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
    {
        toolbar1.frame = CGRectMake(0, 0, 1024, 44);
        toolbar2.frame = CGRectMake(0, 374, 1024, 44);
    }
    else
    {
        toolbar1.frame = CGRectMake(0, 0, 768, 44);
        toolbar2.frame = CGRectMake(0, 502, 768, 44);
    }
}

问题是-什么都没有改变!

我怎么才能修复它?

附注:使用P.S视图时,它可以正常工作

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-06-13 07:41:44

确保您取消选中ViewController.xib中的自动布局,然后此代码将始终有效。更改高度以查看不同,并注释掉其他方法中的所有设置。

代码语言:javascript
复制
- (void)viewDidLayoutSubviews{
    if  (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)){
        toolbar1.frame = CGRectMake(0, 0, 1024, 20);
        toolbar2.frame = CGRectMake(0, 374, 1024, 20);
    } else {
        toolbar1.frame = CGRectMake(0, 0, 768, 44);
        toolbar2.frame = CGRectMake(0, 502, 768, 44);
    }
}
票数 2
EN

Stack Overflow用户

发布于 2013-06-13 08:09:49

我看过你的代码,我知道问题出在哪里。您忘记在代码中将Nib中的元素连接到IBOutlets。

在连接了插座之后,这个示例就可以工作了。我测试过了。

希望这能有所帮助!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17075747

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档