老规矩,先上效果图一张。
废话不多说,直接上代码
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并为发生改变。
网友评论