【问题标题】:Rotation of SubView according to it's superview根据它的超级视图旋转子视图
【发布时间】:2014-03-04 06:00:47
【问题描述】:

我使用带有自动布局支持的故事板创建了一个应用程序。现在我想在请求/响应上添加一个加载视图。我已经通过这样的代码创建了加载视图

self=[super initWithFrame:f];
[self setBackgroundColor:[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.7]];
CGPoint p=[self center];
self.activityIndicator=[[UIActivityIndicatorView alloc] initWithFrame: CGRectMake(p.x-37/2, p.y-32/2, 37, 37)];
[self.activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhite];
[self addSubview:self.activityIndicator];

lblMsg=[[UILabel alloc] initWithFrame:CGRectMake(p.x-50/2,CGRectGetMaxY(self.activityIndicator.frame), 200, 30)];
lblMsg.text=@"Logging...";
lblMsg.backgroundColor=[UIColor clearColor];
lblMsg.textColor=[UIColor lightGrayColor];

[self addSubview:lblMsg];

self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
return self;

现在的问题是它没有执行旋转。它总是以纵向模式出现。我如何对其应用自动旋转功能。

【问题讨论】:

  • 您的应用程序只支持横向模式??还是两者兼而有之??
  • 确定这个加载视图是一个单独的 xib 文件?
  • 不,我是通过代码创建的。这个没有xib。
  • ok,你写的是 YES to should autorotate 方法吗?
  • 它是一个子视图,仅在视图控制器中自动旋转委托方法调用。

标签: ios storyboard subview autorotate


【解决方案1】:

也许这会帮助你尝试这个

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

- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

【讨论】:

    【解决方案2】:

    我找不到您从哪里开始为 UIActivityIndi​​catorView 制作动画。

    [self.activityIndicator startAnimating];
    

    用于加载视图的最佳框架之一

    1) https://github.com/jdg/MBProgressHUD

    【讨论】:

      【解决方案3】:

      您可以使用NetworkActivityIndicator

      当你发送请求时,使用

      [self setNetworkActivityIndicatorVisible:YES];
      

      当响应返回时,使用

      [self setNetworkActivityIndicatorVisible:NO];
      

      【讨论】:

        猜你喜欢
        • 2012-11-28
        • 1970-01-01
        • 2011-08-02
        • 1970-01-01
        • 2016-06-29
        • 2011-10-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多