方向更改时UICollectionView中的分页问题 [英] Issue with pagination in UICollectionView when orientation changes
问题描述
我正在准备一个具有所有方向支持(调整高度和宽度的大小)和分页功能的GridView.
I'm preparing a GridView with all orientation support (height & width resizing) and paging enabled.
在我的示例中,采用了3 * 3网格,并以此进行显示,在最后一页中添加了一些虚拟透明单元格.
In my sample in have taken a 3*3 Grid and to show it like that I have added some dummy transparent cell at the last page.
问题是当我进入最后一页时,我将方向从横向更改为纵向,因此分页不起作用.
The issue is when I'm at last page and there I'm changing my orientation from landscape to portrait the pagination doesn't work.
我在willRotateToInterfaceOrientation
中使用了此代码:
CGPoint scrollTo = CGPointMake(self.frame.size.width * mPageControl.currentPage, 0);
[self setContentOffset:scrollTo animated:YES];
但是,当从横向到纵向以及从纵向变为横向时,静止页面都可以移动到最后一页之前的页面.
But still page moves to a page before the last page when going from landscape to portrait and while changing portrait to landscape it works fine.
推荐答案
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
//Ignoring specific orientations
if (orientation == UIDeviceOrientationFaceUp || orientation == UIDeviceOrientationFaceDown || orientation == UIDeviceOrientationUnknown || currentOrientation == orientation)
{
return;
}
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(relayoutLayers) object:nil];
//Responding only to changes in landscape or portrait
currentOrientation = orientation;
[self performSelector:@selector(handleOrientationChange) withObject:nil afterDelay:0];
然后,只要方向发生变化,我就调用一个方法
Then i'm calling a method whenever orientation is changing
-(void)handleOrientationChange
{
CGRect frame = self.frame;
frame.origin.x = self.frame.size.width * mPageControl.currentPage;
frame.origin.y = 0;
[self scrollRectToVisible:frame animated:YES];
}
这篇关于方向更改时UICollectionView中的分页问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!