• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 奇怪但易于理解的错误... UIActivityIndi​​catorView stopAnimating 不起作用

[复制链接]
菜鸟教程小白 发表于 2022-12-12 09:01:36 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

编辑:UIActivityIndi​​catorView 认为它不在屏幕上...所有值都表明它不在,但是当您查看屏幕时,它就在那里。

所以...这有点让我发疯。

我正在使用 https://github.com/fphilipe/PHFComposeBarView

我正在编辑它,以便在加载时将 UIActivityIndi​​catorView 放在右侧按钮的位置...

就目前而言,我可以完美地开始为 UIActivityIndi​​catorView 设置动画...但是当我必须停止为它设置动画时,它不会停止也不会消失。

我有 hidesWhenStopped = true 并且我知道一切都发生在主线程上。

实际上,当我使用printlnNSLog 时,我看到UIActivityIndi​​catorView 认为它是隐藏的......当它显然不是时。

有人知道为什么它可能不起作用吗?

编辑:我什至尝试通过让 UIActivityIndi​​catorView 始终为动画并只是将其添加到 View 或将其从其 super View 中删除来缓解这种情况......再次,当我需要删除它时,它不起作用。 ..

- (void)startLoading {
    dispatch_async(dispatch_get_main_queue(), ^{
        [[self loadIndicator] startAnimating];

    });
}

- (void)stopLoading {
    dispatch_async(dispatch_get_main_queue(), ^{
        [[self loadIndicator] stopAnimating];
    });
}

@synthesize button = _button;
- (UIButton *)button {
    if (!_button) {
        _button = [PHFComposeBarView_Button buttonWithType:UIButtonTypeCustom];
        CGRect frame = CGRectMake([self bounds].size.width - kHorizontalSpacing - kButtonRightMargin - kButtonTouchableOverlap,
                                  [self bounds].size.height - kButtonBottomMargin - kButtonHeight,
                                  2 * kButtonTouchableOverlap,
                                  kButtonHeight);
        [_button setFrame:frame];
        [_button setTitleEdgeInsets:UIEdgeInsetsMake(0.5f, 0, 0, 0)];
        [_button setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleTopMargin];
        [_button setTitle:[self buttonTitle] forState:UIControlStateNormal];

        UIColor *disabledColor = [UIColor colorWithHue:240.0f/360.0f saturation:0.03f brightness:0.58f alpha:1.0f];
        [_button setTitleColor:disabledColor forState:UIControlStateDisabled];
        UIColor *enabledColor = [UIColor colorWithHue:211.0f/360.0f saturation:1.0f brightness:1.0f alpha:1.0f];
        [_button setTitleColor:enabledColor forState:UIControlStateNormal];
        [_button addTarget:self actionselector(didPressButton) forControlEvents:UIControlEventTouchUpInside];

        UILabel *label = [_button titleLabel];
        [label setFont:[UIFont boldSystemFontOfSize:kFontSize]];
    }

    return _button;
}

@synthesize loadIndicator = _loadIndicator;
- (UIActivityIndicatorView *)loadIndicator {
    if (!_loadIndicator) {

        UIButton *rightButton = [self button];

        _loadIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake([rightButton frame].origin.x + [rightButton frame].size.width / 2.0f - [rightButton frame].size.height / 2.0f, [rightButton frame].origin.y, [rightButton frame].size.height, [rightButton frame].size.height)];

        [_loadIndicator setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleTopMargin];

        _loadIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
        _loadIndicator.hidesWhenStopped = true;

    }

    return _loadIndicator;
}

那应该是相关代码...

在我的 View Controller 中:

var composeBarView: PHFComposeBarView {
    var viewBounds = self.view
    var frame = CGRectMake(0, viewBounds.frame.height - PHFComposeBarViewInitialHeight, viewBounds.frame.width, PHFComposeBarViewInitialHeight)

    var composeBarView = PHFComposeBarView(frame: frame)

    composeBarView.maxLinesCount = 6
    composeBarView.placeholder = "Write some text"
    composeBarView.buttonTitle = "Reply"
    composeBarView.delegate = self

    composeBarView.buttonTintColor = UIColor(hexString: "056A85")
    composeBarView.textView.backgroundColor = UIColor.whiteColor()

    return composeBarView
}



Best Answer-推荐答案


因为您使用的是计算属性,而不是惰性属性,所以每次调用 self.composeBarView 时,您都在创建一个新实例。您的代码使用传递的 View 开始动画,但要停止动画,您总是创建一个显然尚未显示的新 View 。

将您的代码更改为:

lazy var composeBarView: PHFComposeBarView = {
    var viewBounds = self.view
    var frame = CGRectMake(0, viewBounds.frame.height - PHFComposeBarViewInitialHeight, viewBounds.frame.width, PHFComposeBarViewInitialHeight)

    var composeBarView = PHFComposeBarView(frame: frame)

    composeBarView.maxLinesCount = 6
    composeBarView.placeholder = "Write some text"
    composeBarView.buttonTitle = "Reply"
    composeBarView.delegate = self

    composeBarView.textView.backgroundColor = UIColor.whiteColor()

    return composeBarView
}()

关于ios - 奇怪但易于理解的错误... UIActivityIndi​​catorView stopAnimating 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32734416/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap