[英]iOS10 widget “Show more” “Show less” bug
I have implemented the new widget for iOS 10 and I have used the following code to set the height for it: 我已经为iOS 10实现了新的小部件,我使用以下代码为它设置了高度:
@available(iOSApplicationExtension 10.0, *)
func widgetActiveDisplayModeDidChange(activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize) {
if activeDisplayMode == NCWidgetDisplayMode.Compact {
self.preferredContentSize = CGSizeMake(0.0, 350.0)
}
else if activeDisplayMode == NCWidgetDisplayMode.Expanded {
self.preferredContentSize = desiredSize
}
}
And it´s working fine, but my issue is with the "Show more" and "Show less" buttons. 它工作正常,但我的问题是“显示更多”和“显示更少”按钮。 They don't always respond and I do very often have to click more than once to trigger them.
它们并不总是响应,我经常不得不多次点击来触发它们。 I´m I missing something?
我错过了什么? Do I have to add more than the above code to handle the height?
我是否需要添加上述代码才能处理高度?
I had the same issue , the problem was that i had updated the preferredContentSize
even if the widget was in the compact mode. 我遇到了同样的问题,问题是即使小部件处于紧凑模式,我也更新了
preferredContentSize
。
Try to check every place where you update the preferredContentSize
and update the size only if the if widgetActiveDisplayMode
is NCWidgetDisplayModeExpanded
尝试检查更新
preferredContentSize
每个位置,并仅在if widgetActiveDisplayMode
为NCWidgetDisplayModeExpanded
更新大小
Swift 3: 斯威夫特3:
func widgetActiveDisplayModeDidChange(_ activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize) {
if (activeDisplayMode == NCWidgetDisplayMode.compact) {
UIView.animate(withDuration: 0.25, animations: { () -> Void in
self.preferredContentSize = yourFixSize
}, completion: nil)
}
else {
UIView.animate(withDuration: 0.25, animations: { () -> Void in
self.preferredContentSize = yourMaxSize
}, completion: nil)
}
}
had same problem , and I found that when we click the "show more" “show less” button , there is no animation. 有同样的问题,我发现当我们点击“显示更多”“显示更少”按钮时,没有动画。 So you can try to add a block like this :
所以你可以尝试添加这样的块:
- (void)widgetActiveDisplayModeDidChange:(NCWidgetDisplayMode)activeDisplayMode withMaximumSize:(CGSize)maxSize {
if (activeDisplayMode == NCWidgetDisplayModeCompact) {
[UIView animateWithDuration:0.25f
animations:^{
self.preferredContentSize = yourFixSize; }];
}
else {
[UIView animateWithDuration:0.25f
animations:^{
self.preferredContentSize = yourMaxSize;
}];
}
}
I fix this bug in this way . 我以这种方式修复了这个bug。
Hope useful 希望有用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.