iPhone定位-两个盒子
我的iPhone应用程序有两个包含内容的盒子。当用户切换电话盒的方向时,改变如下位置:iPhone定位-两个盒子,iphone,orientation,Iphone,Orientation,我的iPhone应用程序有两个包含内容的盒子。当用户切换电话盒的方向时,改变如下位置: -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ if(toInterfaceOrientation == UIInterfaceOrientationPortrait){ button.fr
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
if(toInterfaceOrientation == UIInterfaceOrientationPortrait){
button.frame = CGRectMake(20,20,125,125);
}else{
button.frame = CGRectMake(20,20,125,125);
}
}
肖像画
|---------|
| BUTTON1 |
| BUTTON2 |
|---------|
| |
| BUTTON3 |
| BUTTON4 |
| |
|---------|
景观
|---------|---------------|
| BUTTON1 | BUTTON3 |
| BUTTON2 | BUTTON4 |
|---------|---------------|
正确的道路是什么?两个XIB,其他技巧?我是否应该在代码中手动调整元素的大小?您可以在视图控制器中使用此方法:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
调整框“/视图”框架。我相信它们会自动设置动画
查看文档以了解更多信息。使用类似以下内容:
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
if(toInterfaceOrientation == UIInterfaceOrientationPortrait){
button.frame = CGRectMake(20,20,125,125);
}else{
button.frame = CGRectMake(20,20,125,125);
}
}
当然,您必须在CGRectMake框中使用自己的维度,但除此之外,我希望这会有所帮助 哼。。。好的,这只是旋转开始时调用的函数。问题是如何调整框的大小。此框包含按钮、其他元素等内容。