【问题标题】:How can i create a horizontal view如何创建水平视图
【发布时间】:2011-01-26 02:41:27
【问题描述】:

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

   - (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),不知道是什么原因。 谢谢!

【问题讨论】:

    标签: iphone objective-c uiview rotation


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 150, 768, 500)]; 如果您不旋转视图,那么坐标系就像纵向模式一样。 尝试 UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(150, 0, 768, 500)];

      【讨论】:

      • 它不起作用。 (0, 150, 768, 500) 左侧和顶部都有空白范围
      • 好吧,然后尝试使用您的 CGRectMake 坐标。没有看到完整的代码,所以不能提供更多帮助。
      猜你喜欢
      • 1970-01-01
      • 2015-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-12
      • 2014-03-21
      • 1970-01-01
      相关资源
      最近更新 更多