简体   繁体   English

根据其父视图旋转SubView

[英]Rotation of SubView according to it's superview

I had created an application using story board with auto layout support. 我使用带有自动布局支持的故事板创建了一个应用程序。 Now i want to add an loading view on request/response. 现在,我想在请求/响应上添加一个加载视图。 I had created loading view by code like this 我已经通过这样的代码创建了加载视图

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;

Now problem is that it is not performing rotation. 现在的问题是它没有执行旋转。 it is always coming in portrait mode. 它总是以纵向模式进入。 How can i apply autorotate functionality to it. 我该如何对其应用自动旋转功能。

may be this will help you try this 也许这会帮助您尝试

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

- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

i couldn't find where you are start animating for UIActivityIndicatorView. 我找不到从哪里开始为UIActivityIndi​​catorView设置动画。

[self.activityIndicator startAnimating];

One of the best framework to use for loadingView 用于loadView的最佳框架之一

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

You can use NetworkActivityIndicator . 您可以使用NetworkActivityIndicator

When you sending the request, use 发送请求时,请使用

[self setNetworkActivityIndicatorVisible:YES];

and when the response come back, use 当回复回来时,使用

[self setNetworkActivityIndicatorVisible:NO];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM