How to mimic the resizable StatusBar in the Spotify iOS app
I've been struggling to figure out how Spotify creates the UI for when the app goes into开发者_开发知识库 offline mode. They make it seem like the StatusBar
has resized, but in reality they're just putting a view below, and resizing all controllers throughout the app. I've tried subclassing UINavigationController
, subclassing UIWindow
, resizing the window, but nothing seems to work for every case.
The interesting thing about the Spotify app, is that their solution seems to still work when iOS' own UIViewController
subclasses are presented modally (as seen in the image below, showing apple's MFMailComposeViewController
- you can tell it's not a custom controller because of the UIBarButtonItems).
If anyone has any insight into how this is possible, that would be awesome.
it's a very dangerous thing to do. I've done in the past and I had nightmares. Below the code that works in iOS4 and supports orientation changes.
- (void) _adjustViewControllerforTicker {
TickerView* vv = [ApplicationContext getTickerView];
if ([PreferenceDataModel isFxTickerOn]&& self.navigationController.view.frame.origin.y==0) {
CGRect tableRect = self.tableView.frame;
self.tableView.frame = CGRectMake(tableRect.origin.x,tableRect.origin.y, tableRect.size.width, tableRect.size.height -20);
UINavigationController *nav = self.navigationController;
CGRect gframe = CGRectOffset(self.navigationController.view.frame, 0, 20);
self.navigationController.view.frame = gframe;
if (!vv) {
vv = [[TickerView alloc] initWithFrame:CGRectMake(0, 0, 480, 20)];
[nav.view addSubview:vv];
[vv release];
self.tableView.contentInset=UIEdgeInsetsMake(0,0,20.0,0.0);
[ApplicationContext setTickerView:vv];
}
if (![PreferenceDataModel isTickerOn]) {
self.tableView.contentInset= UIEdgeInsetsZero;
if (vv){
[vv removeFromSuperview];
vv=nil;
[ApplicationContext setTickerView:nil];
}
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[self _adjustViewControllerforTicker];
}
- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self _adjustViewControllerforTicker];
TickerView* vv = [ApplicationContext getTickerView];
if ([vv count]) {
[vv startAnimation];
}
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self _adjustViewControllerforTicker];
}
And this is how it looks:
精彩评论