如何创建水平视图
当用户旋转设备时,我不想改变我的视图,并且我需要视图在初始化时保持水平。
- (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];
}
问题是应用程序启动时视图不靠近左侧。它仍然有一个空白空间。 我设置的Frame是CGRectMake(0, 150, 768, 500),我不知道原因。 谢谢!
I don't want change 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我无法通过您的问题确定,但是:如果您希望视图处于横向模式,您将需要尝试以下代码:
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:
UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 150, 768, 500)];
如果您不旋转视图,则坐标系类似于纵向模式。
尝试
UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(150, 0, 768, 500)];
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)];