通过将今天的iOS 9扩展转换为iOS 10来解决大小问题 [英] Size problems by converting iOS 9 today extension to iOS 10

查看:120
本文介绍了通过将今天的iOS 9扩展转换为iOS 10来解决大小问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

晚上好!

通过了解今天的扩展程序,我遇到了很大的问题.我已经阅读了很多教程和介绍,但是没有什么可以帮助我理解问题.在iOS 9上,扩展程序可以正常运行-在iOS 10上则不能.

I have big problems by understanding today extensions. I've read lot of tutorials and introductions but nothing helped me to understanding the problem. On iOS 9 the extension works fine - on iOS 10 not.

我的大问题是iOS 10中小部件的自动调整大小(?).在iOS 9中,小部件以纵向和横向完美显示我的表格视图-iOS 10使该组织崩溃并破坏了视图.关于StackOverflow的问题只有这样的答案: https://stackoverflow.com/a/38009125

My big issue is the auto resizing(?) of the widget in iOS 10. On iOS 9 the widget show my table view in portrait and landscape perfect - iOS 10 crash that organization and break the view. The question on StackOverflow about that has only the answers like that: https://stackoverflow.com/a/38009125

但是我不会显示带有更多"/更少"的按钮.我的扩展程序应该仅以特定的高度显示tableView,而不是更多,更少.

But I won't display a button with "more" / "less". My extension should only display my tableView in a specific height, not more, not less.

我今天要测试的扩展名(如果可行,我将用表格视图构建类似的扩展名)是:

The today extension that I use to test (I will build a similar extension with a table view if it works) is that: https://github.com/maximbilan/iOS-Today-Extension-Simple-Tutorial (It's not my code - I'm happy about the work of the publisher!)

以下是该问题的两张图片(1. iOS 9、2.iOS 10):

Here are two pictures of the problem (1. iOS 9, 2. iOS 10):

我不明白这是什么问题.我用self.preferredContentSize.height = 200设置了高度,但iOS 10却不像iOS 9那样使用该高度.上面的StackOverflow答案不是解决方案,因为我不会设置更多/更少的按钮.尽管我使用了更多/更少"按钮的代码,但问题仍然以紧凑的尺寸存在:

I don't understand what is the problem. I set the height with self.preferredContentSize.height = 200 but iOS 10 dont use that height like iOS 9. And the StackOverflow answer above is not a solution because I won't a more / less button. Although I use the code of the more / less button the problem exist anymore in compact size:

// ViewDidLoad
if #available(iOSApplicationExtension 10.0, *) {
        self.extensionContext?.widgetLargestAvailableDisplayMode = NCWidgetDisplayMode.expanded
    } else {
        self.preferredContentSize.height = 200
    }

// method in File
@available(iOSApplicationExtension 10.0, *)
func widgetActiveDisplayModeDidChange(_ activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize) {
    if (activeDisplayMode == NCWidgetDisplayMode.compact) {
        self.preferredContentSize = maxSize
    }
    else {
        self.preferredContentSize = CGSize(width: maxSize.width, height: 200)
    }
}

正如我在上面所说的-仅当将小部件按为显示更多"时,此代码才有效...如果未按下按钮且小部件尺寸紧凑,则它看起来像上面的图像.

As I said above - this code work only if the widget is pressed as "show more"... If the button is not pressed and the widget is in compact size it looks like the image above.

我希望任何人都可以帮助我,因为这是我很长一段时间以来一直遇到的问题,而且我在iOS 10上找不到有关今天的小部件的足够材料.

I hope anybody can help me because that is a problem I have for a really long time and I don't find enough material about today widgets on iOS 10.

谢谢!

推荐答案

是的,我遇到了同样的问题.我用widgetActiveDisplayModeDidChange解决了它,并在viewDidLoad
中对其进行了调用 雨燕3

Yes i had same problem. I solved it with widgetActiveDisplayModeDidChange and I call it in viewDidLoad
Swift 3

func widgetActiveDisplayModeDidChange(_ activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize) {
    self.preferredContentSize = (activeDisplayMode == .expanded) ? CGSize(width: 500, height: 230) : CGSize(width: maxSize.width, height: 110)
}

override func viewDidLoad() {
    super.viewDidLoad()

     self.extensionContext?.widgetLargestAvailableDisplayMode = NCWidgetDisplayMode.expanded

    widgetActiveDisplayModeDidChange(.compact, withMaximumSize: CGSize(width: 500, height: 230))

}

这篇关于通过将今天的iOS 9扩展转换为iOS 10来解决大小问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆