一句话笔记,某段时间内遇到或看到的某个可记录的点。 2017-05-04
- 1、
Storyboard
中用segue
创建popoverVC
时 更改箭头颜色 - 2、注意
UICollectionView
的预加载
一、
Storyboard
中用segue
创建popoverVC
时 更改箭头颜色
在 storyboard 中用 segue 创建 popover 时,如果要更改箭头的颜色(默认是白色):
- 1-1、用常规方法 :
navigationController?.popoverPresentationController?.backgroundColor = myNavBarColor
是没用的;
2-2、而在主
UIViewController
的prepareForSegue
方法中为UIPopoverPresentationController
定义新的UIPopoverBackgroundView
子类又太晚了。2-3、正确的方法是
在prepareForSegue
中使用下面 方法即可
segue.destinationViewController.popoverPresentationController.backgroundColor
知识点备注源自:张嘉夫 微博知识点
自我实现测试:
大致效果
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"GoPopoverTestIden"]) {
UIViewController *popoverVC = segue.destinationViewController;
popoverVC.popoverPresentationController.delegate = self;
popoverVC.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;
popoverVC.popoverPresentationController.sourceRect = self.testButton.bounds;
// 就是这句话,更改颜色,哈哈哈
segue.destinationViewController.popoverPresentationController.backgroundColor = [UIColor greenColor];
}
}
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {
return UIModalPresentationNone;
}
二、注意
UICollectionView
的预加载
预加载
可以看到我们进行滑动时,注意点
- 预加载,自动先加载下一个数据
- 特别到末尾的时候,例如上述最后滑到 6 时,直接滑动 5 时,预加载的却是 4 ,所以此处可以这样理解,它这边是缓存了两个,因为其是复用的嘛
记住上述永远是重用两个的,显示的+ 1嘛
PS:测试中发现 用 Objective-C 和 Swfit 写还有区别的:
- Objective-C 这边是直接一进来直接加载 1; 之后向 2 滑动 的时候,才一起加载 2,预加载 3
- Swift 却是一进来直接加载 1,预加载 2; 之后向 2 滑动的时候,才预加载 3。
感觉这个是很有意思的,其实按个人的理解: Swfit 中的在此处的预加载更符合复用的,机制更合理,感觉确实是 Swfit 确实是一直在优化的。
另外注意下,其预加载中的代理 和 开关,有时很有用。
@protocol UICollectionViewDataSourcePrefetching <NSObject>
@required
// 预加载数据
- (void)collectionView:(UICollectionView *)collectionView prefetchItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths NS_AVAILABLE_IOS(10_0);
@optional
// 取消预加载数据
- (void)collectionView:(UICollectionView *)collectionView cancelPrefetchingForItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths NS_AVAILABLE_IOS(10_0);
@end
@property (nonatomic, weak, nullable) id<UICollectionViewDataSourcePrefetching> prefetchDataSource NS_AVAILABLE_IOS(10_0);
@property (nonatomic, getter=isPrefetchingEnabled) BOOL prefetchingEnabled NS_AVAILABLE_IOS(10_0);
某些情况可以直接设置 prefetchingEnabled
为 NO。
#######