How can i create a horizontal view
I don't want chang开发者_JAVA百科e my view when user rotate the device, and I need the view to be horizontal when it is initialized.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return NO;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self.view setTransform:CGAffineTransformMakeRotation(M_PI / 2)];
UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 150, 768, 500)];
myView.backgroundColor = [UIColor blueColor];
[self.view addSubview:myView];
}
The problem is the view is not close to left side when the app start. It still have a blank space. the Frame I set is CGRectMake(0, 150, 768, 500), I don't know the reason. Thanks!
I can't tell for certain by your question, but: if you want the view to be in landscape mode, you will want to try the following code:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 150, 768, 500)]; If you're not rotating the view, then the coordinate system is like for the portrait mode. try UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(150, 0, 768, 500)];
精彩评论