如何创建水平视图

发布于 2024-10-13 22:18:39 字数 590 浏览 1 评论 0原文

当用户旋转设备时,我不想改变我的视图,并且我需要视图在初始化时保持水平。

   - (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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

独自←快乐 2024-10-20 22:18:40

我无法通过您的问题确定,但是:如果您希望视图处于横向模式,您将需要尝试以下代码:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
   return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

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);
}
心如狂蝶 2024-10-20 22:18:40

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)];

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文