在Today-Extension中获取通知中心的宽度 [英] Getting width of the Notification-Center inside Today-Extension

查看:271
本文介绍了在Today-Extension中获取通知中心的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正试图把一个CollectionView放在今天的扩展。
但是有一些东西让我困扰。

I am currently trying to put a CollectionView inside a Today Extension. But there is some thing that bothers me.

我想实现每个单元格适合我的收藏视图的一行。
所以计算单元格的宽度,取决于项目数量。

I want to achieve that every cell fits inside one row of my collection-view. So calculate the cells width, depending on the items count.

在iPhone上一切正常,但在iPad上它看起来不正确。
单元格宽度是大的。
所以我调试我的代码,似乎self.view.frame.width或self.view.bounds.width
返回屏幕的整个宽度,而不是通知中心宽度。难怪为什么我的细胞是大的。
我计算我的项目大小像这样:

Everything works fine on the iPhone but on the iPad it just doesn't look right. The cells width are way to big. So i debugged my code and it seems that self.view.frame.width or self.view.bounds.width returns the full width of the Screen and not the notification-centers width. No wonder why my cells are to big. I am calculating my item-size like so :

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat count = (CGFloat)[self.collectionView numberOfItemsInSection:0];
    return CGSizeMake(self.collectionView.frame.size.width/count, 80.0);;
}



现在我的问题是,如何获得真实我的通知中心在ipad?

So my question now is, how can i get the "real" width of my notification center on the ipad ?

推荐答案

只是猜测在这里,但从我的经验UICollectionView我会说你会需要在 viewDidLayoutSubviews 中计算您的单元格大小。

Just guessing here, but from my experience with UICollectionView i'd say you will need to calculate your cell size's in viewDidLayoutSubviews.

当您的委托方法被调用时(可能不久之后 viewDidLoad:),视图可能尚未正确调整大小,因此会返回错误的框架大小(所有视图控件都以全屏尺寸初始化,并稍后调整为适合大小)。

When your delegate method gets called (probably shortly after viewDidLoad:) the view might not got properly resized yet and therefore returns the wrong frame size (all viewcontrollers are initialized with the full screen size and are later resized to fit).

中执行viewDidLayoutSubviews 应该保证你的collectionViews框架已经是正确的。您需要重新载入collectionView。

Doing it in viewDidLayoutSubviews should guarantee that your collectionViews Frame is already correct. You'll need to reload your collectionView though.

这篇关于在Today-Extension中获取通知中心的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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