Nic*_*ick 6 iphone objective-c uinavigationcontroller uicollectionview 3dtouch
我有一个嵌入在UINavigationController中的UITableViewController,我正在尝试将Peek&Pop实现到TableView中.我有"偷看"部分完美地工作,但当我尝试"弹出"到下一个ViewController时,我正在"偷看"的单元格和下一个单元格都显示出来.我正在"弹出"到UICollectionView中,正如我所提到的,"peek"一半显示正确的单元格,但"pop"却没有.这个问题只发生在我使用[self.navigationController showViewController:viewControllerToCommit sender:nil];或[self.navigationController pushViewController:viewControllerToCommit animated:YES];执行"pop"时.
我尝试使用[self presentViewController:viewControllerToCommit animated:YES completion:nil];并显示正确的单元格,除了这不会给我我需要的导航元素,所以我不能使用它(除非有办法让所有的导航元素回来).
我最初的想法是,我的应用程序如何计算CollectionViewCell的大小有问题.这是我正在使用的代码,虽然看起来它可以正常使用Peek&Pop以外的所有内容.
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
CGSize collectionViewBounds = collectionView.bounds.size;
int navigationHeight = self.navigationController.navigationBar.bounds.size.height;
int toolbarHeight = self.navigationController.toolbar.bounds.size.height;
int statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;
int cellHeight = collectionViewBounds.height - (navigationHeight + statusBarHeight + toolbarHeight);
int cellWidth = collectionViewBounds.width;
return CGSizeMake(cellWidth, cellHeight);
}
Run Code Online (Sandbox Code Playgroud)
为了增加我的困惑,当"TableView"中的第一个或最后一个项目被"偷看"时,"pop"将完美地运行.任何有关这方面的帮助将不胜感激.
所以我终于弄清楚是什么导致了这个问题。我的应用程序是通用应用程序,我在 iPad 上使用 Popover Segue。在viewWillAppear我的 ViewController 中,“弹出”不正确,我用它[self setPreferredContentSize:CGSizeMake(400.0, 600.0)]来确定 iPad 上 Popover 的大小。一旦我删除了那条线,我的 Peek & Pop 就完美地工作了。
我最终向我的 ViewController 添加了一个新属性@property BOOL fromPeek,并将该属性设置为YES我- (UIViewController *)previewingContext:(id <UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location的预览 ViewController。最后我修改viewWillAppear为be if(!fromPeek) [self setPreferredContentSize:CGSizeMake(400.0, 600.0)];,问题现在解决了!
| 归档时间: |
|
| 查看次数: |
392 次 |
| 最近记录: |