美文网首页
横竖屏切换时UIScrollView偏移量混乱问题

横竖屏切换时UIScrollView偏移量混乱问题

作者: 白菜松 | 来源:发表于2016-12-08 18:09 被阅读178次

1.设备横竖屏切换通知

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientChange:) name:UIDeviceOrientationDidChangeNotification object:nil];

- (void)orientationDidChange:(NSNotification *)notification
{
    UIDeviceOrientation  orient = [UIDevice currentDevice].orientation;
    //需要重新设置contentSize,contentOffset
    _collectionView.contentSize = CGSizeMake(_arrPageModel.count * self.view.frame.size.width,self.view.frame.size.height);
    _collectionView.contentOffset = CGPointMake(_currentIndexPath.item * self.view.frame.size.width, 0);
}

相关文章

网友评论

      本文标题:横竖屏切换时UIScrollView偏移量混乱问题

      本文链接:https://www.haomeiwen.com/subject/fopsmttx.html