一句话笔记,某段时间内遇到或看到的某个可记录的点。 2017-05-12
- 注释的另一种用法
- contentOffset.y 的不精确
- UIApplicationRotationFollowingController 的出现
一、注释的另一种用法
一般情况下,下面两种注释是我们最常用的:
/**
测试字符串
*/
@property (nonatomic, copy) NSString *testStr;
@property (nonatomic, strong) UIView *testView; // 测试 视图
![](https://img.haomeiwen.com/i784630/018631e73ef8315d.png)
@property (nonatomic, strong) NSArray *testArray; ///< 测试数组
![](https://img.haomeiwen.com/i784630/fdf3d2fd60954efa.png)
此种方法,有时在不想代码那么过长的情况下,可以尝试。
二、contentOffset.y 的不精确
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
}
contentOffset.y == 907.000000, headerViewHeight == 902.439987
contentOffset.y == 906.000000, headerViewHeight == 902.439987
contentOffset.y == 905.500000, headerViewHeight == 902.439987
contentOffset.y == 905.000000, headerViewHeight == 902.439987
contentOffset.y == 904.500000, headerViewHeight == 902.439987
contentOffset.y == 904.000000, headerViewHeight == 902.439987
contentOffset.y == 903.500000, headerViewHeight == 902.439987
contentOffset.y == 903.000000, headerViewHeight == 902.439987
上述在打印 scrollView
中 contentOffset.y
时发现其值无法精准,永远是以 0.5
的精度在变化,此时例如旁边的 902.439987
就永远无法等于啦。
- 所以需要注意有时我们对这个值判断是不准确的
- 另外可以对,类似
902.439987
, 进行ceilf
或floorf
处理。
ceilf(_headerViewHeight); // 向上取值
floorf(_headerViewHeight); // 向下取值
三、 UIApplicationRotationFollowingController 的出现
出现 UIApplicationRotationFollowingController
这个的原因是,当我去获取:
controller = [UIApplication sharedApplication].keyWindow.rootViewController;
发现居然是:
po [controller class] // === UIApplicationRotationFollowingController
原因: 此处是由于 keyWindow 已经发生改变,在最上一层就是 UIApplicationRotationFollowingController,下面的才是我们想要获取的。
解决的办法,获取 RootViewController
换一个方式:
- 方法一: .delegate
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
UIViewController *rootViewController = appDelegate.window.rootViewController;
- 方法二: 或者直接获取自己的要的 TabBarViewController
NSArray<UIWindow *> *windows = [UIApplication sharedApplication].windows;
__block PQTabBarController *rootViewController ;
[windows enumerateObjectsUsingBlock:^(UIWindow * subWindow, NSUInteger idx, BOOL * _Nonnull stop) {
if ([subWindow.rootViewController isKindOfClass:[PQTabBarController class]]) {
rootViewController = (PQTabBarController *)subWindow.rootViewController;
* stop = YES;
}
}];
网友评论