一句話筆記,某段時間內遇到或看到的某個可記錄的點。 2017-05-12
- 注釋的另一種用法
- contentOffset.y 的不精確
- UIApplicationRotationFollowingController 的出現
一、注釋的另一種用法
一般情況下,下面兩種注釋是我們最常用的:
/**
測試字符串
*/
@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
上述在打印 scrollView
中 contentOffset.y
時發現其值無法精準,永遠是以 0.5
的精度在變化,此時例如旁邊的 902.439987
就永遠無法等于啦。
- 所以需要注意有時我們對這個值判斷是不準確的
- 另外可以對,類似
902.439987
, 進行ceilf
或floorf
處理。
ceilf(_headerViewHeight); // 向上取值
floorf(_headerViewHeight); // 向下取值
三、 UIApplicationRotationFollowingController 的出現
出現 UIApplicationRotationFollowingController
這個的原因是,當我去獲?。?/p>
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;
}
}];