xcode iOS 8 Today Extension 的最大高度?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24815957/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maximum height of iOS 8 Today Extension?
提问by user2816488
I am working on a Today Extension with a dynamically sized table. I have been able to get the table to resize for the content using:
我正在使用动态大小的表格开发 Today Extension。我已经能够使用以下方法调整表格的内容大小:
self.preferredContentSize = accountsTable.contentSize
However, I have found that it will not get taller than a certain size (568 px) even though I can tell the table contentSize is larger.
但是,我发现它不会超过特定大小(568 像素),即使我可以告诉表 contentSize 更大。
I'm not clear if this is a built-in limit or if there is a way around this to make a larger view. It appears that some previous extensions (Stocks widget) is able to become larger.
我不清楚这是否是一个内置限制,或者是否有办法解决这个问题以扩大视野。似乎一些以前的扩展(股票小部件)能够变得更大。
Anyone else running into the same behavior. Anyone know if it's possible to make an extension appear larger either immediately or using a "Show All" button like the Stock widget?
其他任何人都会遇到同样的行为。任何人都知道是否可以立即或使用“全部显示”按钮(如股票小部件)使扩展程序显得更大?
采纳答案by Urkman
I made some tests and you can calculate the maximum height of your Today Extension with this formular:
我做了一些测试,你可以用这个公式计算你今天扩展的最大高度:
for iPhone:
对于 iPhone:
float maxHeight = [[ UIScreen mainScreen ] bounds ].size.height - 126;
for iPad:
对于 iPad:
float maxHeight = [[ UIScreen mainScreen ] bounds ].size.height - 171;
This should work for alle Screen sizes...
这应该适用于所有屏幕尺寸......
回答by Bart?omiej Semańczyk
Ok, although you can assign to the preferredContentSize
any CGSize
it is reduced to max height and width.
好的,尽管您可以将其分配给preferredContentSize
任何CGSize
减少到最大高度和宽度的对象。
DeviceOrientation (max width, max height):
设备方向(最大宽度,最大高度):
iPhone 5SPortrait (272, 441.5)
iPhone 5SLandscape (520, 205.5)iPhone 6Portrait (327, 540.5)
iPhone 6Landscape (586, 260.5)iPhone 6 PlusPortrait (362, 610)
iPhone 6 PlusLandscape (585, 288)iPad MiniPortrait (535, 853)
iPad MiniLandscape (535, 597)iPadPortrait (711, 985)
iPadLandscape (967, 729)
iPhone 5S人像 ( 272, 441.5)
iPhone 5S风景 ( 520, 205.5)iPhone 6纵向 ( 327, 540.5)
iPhone 6横向 ( 586, 260.5)iPhone 6 Plus人像 ( 362, 610)
iPhone 6 Plus风景 ( 585, 288)ipad公司赠送人像(535,853)
的iPad赠送景观(535,597)iPad的人像(711,985)
的iPad景观(967,729)
How did I get these values?
我是如何获得这些值的?
@IBOutlet weak var sizerView: UIView!
inside viewDidLoad:
里面 viewDidLoad:
preferredContentSize = CGSizeMake(0, 2000)
dispatch_after(1, dispatch_get_main_queue(), { //it needs time to render itself
label.text = NSStringFromCGSize(self.sizerView.bounds.size) //here you have MAX VALUES
}
回答by gklka
It seems, that iOS is adding an UIView-Encapsulated-Layout-Height
constraint to your own constraints:
看来,iOS 正在向UIView-Encapsulated-Layout-Height
您自己的约束添加约束:
(
"<NSLayoutConstraint:0x610000280640 V:[_UILayoutGuide:0x7f92d0513810]-(500)-[UILabel:0x7f92d040cb20'Hello World']>",
"<NSLayoutConstraint:0x610000280690 V:[UILabel:0x7f92d040cb20'Hello World']-(500)-[_UILayoutGuide:0x7f92d0515100]>",
"<_UILayoutSupportConstraint:0x6100002a2f40 V:[_UILayoutGuide:0x7f92d0513810(0)]>",
"<_UILayoutSupportConstraint:0x6100002a2ee0 V:|-(0)-[_UILayoutGuide:0x7f92d0513810] (Names: '|':UIView:0x7f92d040c810 )>",
"<_UILayoutSupportConstraint:0x6100002a3000 V:[_UILayoutGuide:0x7f92d0515100(0)]>",
"<_UILayoutSupportConstraint:0x6100002a2fa0 _UILayoutGuide:0x7f92d0515100.bottom == UIView:0x7f92d040c810.bottom>",
"<NSLayoutConstraint:0x60800009e780 'UIView-Encapsulated-Layout-Height' V:[UIView:0x7f92d040c810(628)]>"
)
This constraint forces the widget to have the maximum height. You can get it's value like this:
此约束强制小部件具有最大高度。你可以得到它的价值是这样的:
- (void)widgetPerformUpdateWithCompletionHandler:(void (^)(NCUpdateResult))completionHandler {
for (NSLayoutConstraint *constraint in self.view.constraints) {
if ([constraint.identifier isEqualToString:@"UIView-Encapsulated-Layout-Height"]) {
NSLog(@"Height: %@", @(constraint.constant));
}
}
completionHandler(NCUpdateResultNewData);
}
回答by MobileMon
To get the max height of the widgets active display mode, do this in your UIViewController:
要获得小部件活动显示模式的最大高度,请在您的 UIViewController 中执行此操作:
let context = self.extensionContext
if let context = context{
let height = context.widgetMaximumSize(for: context.widgetActiveDisplayMode).height
}
To get the max height of expanded and compact individually regardless of the current display mode, do this:
无论当前显示模式如何,要单独获得扩展和压缩的最大高度,请执行以下操作:
var context = self.extensionContext
if let context = context{
let compactHeight = context.widgetMaximumSize(for: .compact).height
let expandedHeight = context.widgetMaximumSize(for: .expanded).height
}
回答by Notive
The recommended way is to use auto-layout constraints to constrain your view's height.
推荐的方法是使用自动布局约束来约束视图的高度。
It seems the 568px is just the maxheight of your iPhone 5 and not the actual size. As far as I could figure out there is no way to get the real size.
看起来 568px 只是你的 iPhone 5 的最大高度,而不是实际大小。据我所知,无法获得真实尺寸。