【问题标题】:Activity Indicator is not showing in front of view活动指示器未显示在视图前面
【发布时间】:2023-04-07 22:00:01
【问题描述】:

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

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

案例1:当我在self.view中添加activity Indicator时,它显示在UIScrollView后面意味着根本不显示。

案例 2:如果我将指示器添加到 Scrollview,它不会添加到视图中。

我尝试了很多东西 bringSubviewToFront , insertSubview:indicator aboveSubview:myscrollview

这是我的代码:

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




}

【问题讨论】:

  • 你试过在主线程上显示它吗?尝试 viewDebugging 来找出根本原因。
  • 您正在将 UIActivityIndi​​catorView 添加到您的视图中,但您在选择器委托中的代码会检查您的选择器委托。因此这将显示一个新的视图控制器。它不会显示您的指示器
  • 指标在视图上添加,但在滚动视图下方。

标签: ios uiscrollview uiactivityindicatorview


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2016-12-12
    • 2016-06-25
    • 1970-01-01
    • 2012-01-25
    • 2019-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多