iOS7:出现在UINavigationBar下的UICollectionView
我已经在iOS 7上构build了一段时间,但是我还没有解决这个问题,我有许多在Storyboard中创build的自动布局的视图,并且使用标准的UINavigationController
来显示。 大多数都很好,但基于UICollectionView
的那些总是将自己置于导航栏下,除非我将半透明设置为NO
。 我尝试了edgesExtended
技巧,但似乎并没有解决它,我不一定介意半透明,但我想解决它更干净。
我之前有过这个问题,只是用顶边距设置集合视图的边缘提示:
[self.myCollectionVC.collectionView setContentInset:UIEdgeInsetsMake(topMargin, 0, 0, 0)];
其中,topMargin是导航栏的大小,或者您希望集合开始滚动的任何点。
这样,您的collections视图将在导航栏的正下方开始滚动,同时它将填充整个屏幕,如果导航栏是半透明的,您将看到它。
仅供参考如果您的UICollectionView是视图控制器的层次结构中的根视图,并且您的视图控制器已automaticallyAdjustsScrollViewInsets
将AdjustsScrollViewInsets设置为YES(这是默认设置),那么contentInset应自动更新。
但是,如果您的scrollview(或tableview / collectionview / webview btw)是其视图控制器层次结构中的第一个视图,那么scrollview的contentInset只会自动更新。
我经常在我的层次结构中首先添加一个UIImageView以获得背景图像。 如果你这样做,你必须在viewDidLayoutSubviews中手动设置scrollview的边缘插入:
- (void) viewDidLayoutSubviews { [super viewDidLayoutSubviews]; CGFloat top = self.topLayoutGuide.length; CGFloat bottom = self.bottomLayoutGuide.length; UIEdgeInsets newInsets = UIEdgeInsetsMake(top, 0, bottom, 0); self.collectionView.contentInset = newInsets; }
我使用的是swift和xcode 7.3.1。 我解决了故事板,select我的导航控制器,然后取消select“扩展边缘”“顶部吟游诗人”。
-(void) viewDidiLoad{ self.automaticallyAdjustsScrollViewInsets = NO;//added important } - (void) viewDidLayoutSubviews { [super viewDidLayoutSubviews]; CGFloat top = self.topLayoutGuide.length; CGFloat bottom = self.bottomLayoutGuide.length; UIEdgeInsets newInsets = UIEdgeInsetsMake(top, 0, bottom, 0); self.collectionView.contentInset = newInsets; }
- 现在提交iOS 7应用程序?
- Iphone presentLocalNotificationNow不触发警报和声音,而应用程序在后台
- XCode 5 / iOS 7 – 本地化不能在模拟器中工作
- 通过3类课程来破解PokemonGo iOS应用
- 在iOS中发送包含AVPlayer请求的标头
- 与Objective-C不同的Swift功能
- 设置AVAudioTimePitchAlgorithmVarispeed为AVFoundationAudioSettings
- iOS Quartz在pdf中embedded字体
- iOS将一个CollectionView添加到storyboard UI构build器中的另一个视图