Maximum Height of iOS 8 Today Extension

Maximum height of iOS 8 Today Extension?

I made some tests and you can calculate the maximum height of your Today Extension with this formular:

for iPhone:

float maxHeight = [[ UIScreen mainScreen ] bounds ].size.height - 126;

for iPad:

float maxHeight = [[ UIScreen mainScreen ] bounds ].size.height - 171;

This should work for alle Screen sizes...

How to set the height of a Today Widget Extension?

In your widget UIViewController.m (Objective-C):

self.preferredContentSize = CGSizeMake(0, 200);

Will make your widget have a height of 200.

Note that the width will have no affect on the view, as widgets must fit in the exact width of notification center, which is handled automagically.

Also, if you want to animate changes in the height of your view, you can implement (Objective-C):

- (void)viewWillTransitionToSize:(CGSize)size
withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator

in your view controller using -animateAlongsideTransition:completion:

The answer was a bit hidden; you had to click around in the documentation sidebar to eventually find this fantastic document.



Another way is to use auto-layout constraints to constrain your view's height.

Today Widget Extension Height - iOS10

The height of the widget in iOS 10 is exactly 110 in compact mode. It can be set to whatever height you want in expanded mode, but in compact mode it will always be 110 and that can't be overwritten.

How to resize the height of today Extension?

I write to the didReceiveMemoryWarning but the correct is to write to the viewDidLoad

  override func viewDidLoad() {
super.viewDidLoad()
self.extensionContext?.widgetLargestAvailableDisplayMode = NCWidgetDisplayMode.expanded}

func widgetActiveDisplayModeDidChange(_ activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize) {
if activeDisplayMode == NCWidgetDisplayMode.compact {
//compact
self.preferredContentSize = maxSize
} else {
//extended
self.preferredContentSize = CGSize(width: 0, height: 200)
}

Height of iOS8 Today Extension using Only Auto Layout Gives Broken Constraints

After some experimenting, and stumbling across "what is NSLayoutConstraint "UIView-Encapsulated-Layout-Height" and how should I go about forcing it to recalculate cleanly" I determined that you can circumvent this problem using either "Height" & "Equal Heights" OR "Height" and Top and Bottom "Vertical Space" (as suggested by Guilherme Sprint), and then decreasing the "Priority" of the height constraint to 999.

Height Constraint with Reduced Priority

This isn't the answer I was hoping for, but it does specify the height of the container via Auto Layout of the subview and avoids any warnings about broken constraints.

My entirely unscientific guess/assumption/conclusion is that iOS is correctly looking at the layout constraints to determine the height of the container view. It then adds a new constraint that is the same height as what it just calculated, but this now over-constrains the height. Reducing the priority on the original developer specified height constraint means the system generated constraint wins out and no warning is generated (would love to hear more about this from someone who actually knows).

Today widgets height issue

From my experience, this option is not currently available to third-party today extensions. The extension environment limits the height, and requesting more has no effect. What's worse is that the actual limit varies depending on screen size, and there's no way to discover the limit at run time except by trial and error.

Apple's apps, and now extensions, have often been exempt from rules that govern third party software. This appears to be another case where this is happening.

I filed a bug (rdar://18408718 in case anyone from Apple sees this) and I encourage you to do the same.

Today Extension: How to work with display mode?

Ok, i found right solution here.

1) Set the display mode to NCWidgetDisplayMode.expanded first in viewDidLoad:

override func viewDidLoad() {
super.viewDidLoad()
self.extensionContext?.widgetLargestAvailableDisplayMode = NCWidgetDisplayMode.expanded
}

2) Implement new protocol method:

func widgetActiveDisplayModeDidChange(_ activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize) {
if (activeDisplayMode == NCWidgetDisplayMode.compact) {
self.preferredContentSize = maxSize
}
else {
//expanded
self.preferredContentSize = CGSize(width: maxSize.width, height: 200)
}
}

And it will work as official apps.

Image



Related Topics



Leave a reply



Submit