热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

今天iOS10中的小部件没有扩展-TodaywidgetiniOS10isnotexpanding

Imtryingtosolveanissuewithmytodaywidget.ItsnotexpandingoniOS10afterpressingShow

I'm trying to solve an issue with my today widget. It's not expanding on iOS10 after pressing "Show more" button. It's size keeps the same all the time.

我正试图解决我今天的小部件的问题。按“显示更多”按钮后,它不会在iOS10上扩展。它的大小始终保持不变。

Here is the code for TodayViewController.swift

这是TodayViewController.swift的代码

import UIKit
import NotificationCenter

class TodayViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        extensionContext?.widgetLargestAvailableDisplayMode = .expanded
    }
}

extension TodayViewController: NCWidgetProviding {

    func widgetActiveDisplayModeDidChange(activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize) {
        if activeDisplayMode == .expanded {
            preferredCOntentSize= CGSize(width: 0, height: 280)
        } else {
            preferredCOntentSize= maxSize
        }
    }
}

Any hints please?

有什么提示吗?

1 个解决方案

#1


8  

Assuming that you are coding using Swift 3, please note that widgetActiveDisplayModeDidChange method signature is:

假设您使用Swift 3进行编码,请注意widgetActiveDisplayModeDidChange方法签名是:

optional func widgetActiveDisplayModeDidChange(_ activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize)

可选的func widgetActiveDisplayModeDidChange(_ activeDisplayMode:NCWidgetDisplayMode,withMaximumSize maxSize:CGSize)

So, it should be:

所以,它应该是:

func widgetActiveDisplayModeDidChange(_ activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize) {
    if activeDisplayMode == .expanded {
        preferredCOntentSize= CGSize(width: 0, height: 280)
    } else {
        preferredCOntentSize= maxSize
    }
}

To double check that it is the problem, you can add a breakpoint to your current method and check if it's reachable or not.

要仔细检查是否存在问题,可以在当前方法中添加断点并检查它是否可访问。


推荐阅读
author-avatar
我是小章丘
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有