I am building an iOS Today widget, and while testing for iOS 10 I noticed that all widgets are now being given the same height (previous versions allowed the dev to set the height). What is the ideal height/what is the best practice for dealing with this new limitation? I'm in swift and I didn't use autolayout fyi. Thanks in advance!
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Using if let syntax in switch statement
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- Enum with associated value conforming to CaseItera
The widget in iOS 10 has been changed as you have noticed and does now have a fixed height. There has also been added new features to the today extension. On of them is the
NCWidgetDisplayMode
. Basically you have a button up in the right corner where you can "Show more" or "Show less".Begin by adding the following to your
viewDidLoad()
What you then need to do is to basically add the following method:
Swift version:
Objective-C version:
Note two things here:
Xcode will automatically suggest that you add the available check for the iOS version (for Swift at least). So do not remove the old way to do this
self.preferredContentSize = CGSizeMake...
This is still needed for older iOS versions.In the
widgetActiveDisplayModeDidChange
functionactiveDisplayMode == NCWidgetDisplayMode.Compact
will be called when you go from "Show more" > "Show less". This is because it´s trigged immediately from the iOS system. AndactiveDisplayMode == NCWidgetDisplayMode.Expanded
will be called when you go from "Show less" > "Show more".And one last thing, this is kind of buggy still with the "Show more" and "Show less" buttons and it´s not fixed yet by Apple. Check the demonstration from Apples Keynote and you will notice that he had the bug issue with this.
Simply do the following:
you can use both:
.compact
and.expanded
types.In iOS 10, by default, the height of today widget is fixed. Moreover, the minimum height of collapsed widget is limited.
These notes are from iOS Human Interface Guidelines.
We can do the following to change it.
First of all, you need to add these codes in your
viewDidLoad
, this makes your widget supports two modes which are new in iOS 10.Swift Version:
ObjC Version:
And then implement the protocol method like:
Swift Version:
ObjC Version:
Run your target, you will see a "Show More" button on right corner of your widget. Tap it and you will see the change.
See more detail: How to resize the height of widget in iOS 10?