ios - 奇怪但易于理解的错误... UIActivityIndicatorView stopAnimating 不起作用
<p><p>编辑:UIActivityIndicatorView 认为它不在屏幕上...所有值都表明它不在,但是当您查看屏幕时,它就在那里。</p>
<p>所以...这有点让我发疯。</p>
<p>我正在使用 <a href="https://github.com/fphilipe/PHFComposeBarView" rel="noreferrer noopener nofollow">https://github.com/fphilipe/PHFComposeBarView</a> </p>
<p>我正在编辑它,以便在加载时将 UIActivityIndicatorView 放在右侧按钮的位置...</p>
<p>就目前而言,我可以完美地开始为 UIActivityIndicatorView 设置动画...但是当我必须停止为它设置动画时,它不会停止也不会消失。</p>
<p>我有 <code>hidesWhenStopped = true</code> 并且我知道一切都发生在主线程上。</p>
<p>实际上,当我使用<code>println</code> 或<code>NSLog</code> 时,我看到UIActivityIndicatorView 认为它是隐藏的......当它显然不是时。</p>
<p>有人知道为什么它可能不起作用吗?</p>
<p>编辑:我什至尝试通过让 UIActivityIndicatorView 始终为动画并只是将其添加到 View 或将其从其 superView 中删除来缓解这种情况......再次,当我需要删除它时,它不起作用。 ..</p>
<pre><code>- (void)startLoading {
dispatch_async(dispatch_get_main_queue(), ^{
[ startAnimating];
});
}
- (void)stopLoading {
dispatch_async(dispatch_get_main_queue(), ^{
[ stopAnimating];
});
}
@synthesize button = _button;
- (UIButton *)button {
if (!_button) {
_button = ;
CGRect frame = CGRectMake(.size.width - kHorizontalSpacing - kButtonRightMargin - kButtonTouchableOverlap,
.size.height - kButtonBottomMargin - kButtonHeight,
2 * kButtonTouchableOverlap,
kButtonHeight);
;
;
;
forState:UIControlStateNormal];
UIColor *disabledColor = ;
;
UIColor *enabledColor = ;
;
;
UILabel *label = ;
];
}
return _button;
}
@synthesize loadIndicator = _loadIndicator;
- (UIActivityIndicatorView *)loadIndicator {
if (!_loadIndicator) {
UIButton *rightButton = ;
_loadIndicator = [ initWithFrame:CGRectMake(.origin.x + .size.width / 2.0f - .size.height / 2.0f, .origin.y, .size.height, .size.height)];
;
_loadIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
_loadIndicator.hidesWhenStopped = true;
}
return _loadIndicator;
}
</code></pre>
<p>那应该是相关代码...</p>
<p>在我的 ViewController 中:</p>
<pre><code>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
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>因为您使用的是计算属性,而不是惰性属性,所以每次调用 <code>self.composeBarView</code> 时,您都在创建一个新实例。您的代码使用传递的 View 开始动画,但要停止动画,您总是创建一个显然尚未显示的新 View 。</p>
<p>将您的代码更改为:</p>
<pre><code>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
}()
</code></pre></p>
<p style="font-size: 20px;">关于ios - 奇怪但易于理解的错误... UIActivityIndicatorView stopAnimating 不起作用,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/32734416/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/32734416/
</a>
</p>
页:
[1]