moveStatusBar.gif
老規矩,先上效果圖一張。
廢話不多說,直接上代碼
NSString *key = [[NSString alloc] initWithData:[NSData dataWithBytes:(unsigned char []){0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x42, 0x61, 0x72} length:9] encoding:NSASCIIStringEncoding];
id object = [UIApplication sharedApplication];
UIView *statusBar;
if ([object respondsToSelector:NSSelectorFromString(key)]) {
statusBar = [object valueForKey:key];
}
[UIView animateWithDuration:.5 animations:^{
statusBar.transform = CGAffineTransformMakeTranslation(x, y);
}];
該方法可以再做側方庫時候使用,也可以在隱藏狀態欄而不想失去那20像素的高度時候使用。注意只是移動了transform,而狀態欄實際的frame并為發生改變。