我在一个ViewControler中有2个UIToolbar。
我需要改变他们轮换的位置。
我增加了2个插座
@property (nonatomic, retain) IBOutlet UIToolbar *toolbar1;
@property (nonatomic, retain) IBOutlet UIToolbar *toolbar2;立即在视图控制器的IB中连接它们。我使用以下代码
- (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视图时,它可以正常工作



发布于 2013-06-13 07:41:44
确保您取消选中ViewController.xib中的自动布局,然后此代码将始终有效。更改高度以查看不同,并注释掉其他方法中的所有设置。
- (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);
}
}发布于 2013-06-13 08:09:49
我看过你的代码,我知道问题出在哪里。您忘记在代码中将Nib中的元素连接到IBOutlets。

在连接了插座之后,这个示例就可以工作了。我测试过了。
希望这能有所帮助!

https://stackoverflow.com/questions/17075747
复制相似问题