iOS 常见坑

一句话笔记(25)(小点)

2017-05-12  本文已影响109人  天空中的球

一句话笔记,某段时间内遇到或看到的某个可记录的点。 2017-05-12

一、注释的另一种用法

一般情况下,下面两种注释是我们最常用的:


/**
    测试字符串
 */
@property (nonatomic, copy) NSString *testStr;

@property (nonatomic, strong) UIView *testView; // 测试 视图

常用的注释
@property (nonatomic, strong) NSArray *testArray; ///< 测试数组
另一种注释方法

此种方法,有时在不想代码那么过长的情况下,可以尝试。

二、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

上述在打印 scrollViewcontentOffset.y 时发现其值无法精准,永远是以 0.5 的精度在变化,此时例如旁边的 902.439987 就永远无法等于啦。

ceilf(_headerViewHeight);  // 向上取值
floorf(_headerViewHeight);  // 向下取值

三、 UIApplicationRotationFollowingController 的出现

出现 UIApplicationRotationFollowingController 这个的原因是,当我去获取:

controller = [UIApplication sharedApplication].keyWindow.rootViewController;

发现居然是:

 po [controller class]   // ===  UIApplicationRotationFollowingController

原因: 此处是由于 keyWindow 已经发生改变,在最上一层就是 UIApplicationRotationFollowingController,下面的才是我们想要获取的。

解决的办法,获取 RootViewController 换一个方式:

 AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
 UIViewController *rootViewController = appDelegate.window.rootViewController;
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;
     }
}];
上一篇 下一篇

猜你喜欢

热点阅读