我在willAnimateRotationToInterfaceOrientation中有以下方法:
-(void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (toInterfaceOrientation == UIInterfaceOrientationPortrait) {
button1.frame = CGRectMake(20, 20, 125, 125);
button2.frame = CGRectMake(175, 20, 125, 125);
NSLog(@"is portrait");
}else{
button1.frame = CGRectMake(20, 20, 125, 125);
button2.frame = CGRectMake(175, 155, 125, 125);
NSLog(@"is landscape");
}
}
当我旋转iOS模拟器时,我可以看到日志出现,这意味着调用了此方法。但是,按钮的框架不会改变。有人可以帮我吗?
我找到了一些关于更改viewWillAppeaer方法或类似事情的相关答案,但没有一个能够解决。
答案 0 :(得分:0)
您还需要强制重绘按钮,您可以通过在方法底部添加两行来执行此操作:
-(void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration
{
if (toInterfaceOrientation == UIInterfaceOrientationPortrait) {
button1.frame = CGRectMake(20, 20, 125, 125);
button2.frame = CGRectMake(175, 20, 125, 125);
NSLog(@"is portrait");
}else{
button1.frame = CGRectMake(20, 20, 125, 125);
button2.frame = CGRectMake(175, 155, 125, 125);
NSLog(@"is landscape");
}
[button1 setNeedsDisplay];
[button2 setNeedsDisplay];
}