本人刚刚接触IOS开发,今天试了一个小例子:想把这个效果变成但是结果却一直这样
请问各位大神怎么解决啊?
我的是IOS SDK6.0
下边是ViewController.m代码
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize buttonUL;
@synthesize buttonUR;
@synthesize buttonL;
@synthesize buttonR;
@synthesize buttonLL;
@synthesize buttonLR;
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{
//if(UIInterfaceOrientationIsPortrait(toInterfaceOrientation))
if(interfaceOrientation == UIInterfaceOrientationPortrait ||interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
buttonUL.frame = CGRectMake(20, 20, 125, 125);
buttonUR.frame = CGRectMake(175, 20, 125, 125);
buttonL.frame = CGRectMake(20, 168, 125, 125);
buttonR.frame = CGRectMake(175, 168, 125, 125);
buttonLL.frame = CGRectMake(20, 316, 125, 125);
buttonLR.frame = CGRectMake(175, 316, 125, 125);
}
else
{
buttonUL.frame = CGRectMake(20, 20, 125, 125);
buttonUR.frame = CGRectMake(20, 155, 125, 125);
buttonL.frame = CGRectMake(177, 20, 125, 125);
buttonR.frame = CGRectMake(177, 155, 125, 125);
buttonLL.frame = CGRectMake(328, 20, 125, 125);
buttonLR.frame = CGRectMake(328, 155, 125, 125);
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
//struct CGPoint {
// CGFloat x;
// CGFloat y;
//};
//typedef struct CGPoint CGPoint;
//struct CGSize {
// CGFloat width;
// CGFloat height;
//};
//typedef struct CGSize CGSize;
- (void)viewDidLoad
{
self.buttonUL = nil;
self.buttonUR = nil;
self.buttonL = nil;
self.buttonR = nil;
self.buttonLL = nil;
self.buttonLR = nil;
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
------解决方案--------------------
你可以在控制器中重写viewDidLayoutSubviews 方法。在这个方法中根据方向重新调整它们的坐标位置。
------解决方案--------------------
如果对于相对复杂的视图,代码量可能要大一些。不过还有一种方法,就是创建两个view,一个横向,一个竖向。根据屏幕的方向再选择加载哪个视图。