活动指标未显示在视图前

时间:2016-03-16 10:45:46

标签: ios uiscrollview uiactivityindicatorview

我有一个视图,其中添加了UIScrollview。在UIScrollView中,我添加了一个UIImageView。从ImagePicker中挑选图片后,我将图像添加到UIImageView。

问题:我在将图像添加到ImageView之前显示UIActivityIndi​​catorView。

案例1:当我向self.view添加活动指示器时,它显示在UIScrollView后面,表示根本没有显示。

案例2:如果我向Scrollview添加指标,则不会在视图中添加。

我尝试了很多东西 bringSubviewToFront,insertSubview:指标上面的子视图:myscrollview

这是我的 CODE:

  scroller = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 60, Screen_width, Screen_height - 60)];
scroller.delegate = self;
[self.view addSubview:scroller];
scroller.contentSize = CGSizeMake(Screen_width, 667);


profileImageView = [[UIImageView alloc]initWithFrame:CGRectMake(20, 10, Screen_width-40, Screen_width-40)];
profileImageView.backgroundColor = gray;
profileImageView.contentMode = UIViewContentModeScaleAspectFill;
profileImageView.clipsToBounds = YES;
profileImageView.userInteractionEnabled=YES;


-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{

_profileIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
_profileIndicator.frame = CGRectMake(40.0, 20.0, 60.0, 60.0);
_profileIndicator.center = self.view.center;
[self.view addSubview:_profileIndicator];
[_profileIndicator startAnimating];




}

1 个答案:

答案 0 :(得分:0)

所有UI内容都应该在主线程中。因此,请确保您在主线程中使用UIActivityIndi​​cator。