I am trying to implement an alert/notification bar that will appear at the bottom of the page, and when clicked will scroll up and cover the entire screen (just like Kayak or PageOnce apps show it). Here’s how it looks right now (Have uploaded the images at below URLs):
Image showing alerts bar at the bottom
http://www.anony.ws/hLe
Alerts bar opened up
http://www.anony.ws/hLl
It works but not completely. One thing, the alert view is not able to cover the navigation bar (alert frame’s origin y is 0 in the attached screenshot for opened up view). If I make the frame’s y negative to go further up, the view goes behind the navigation bar. How can I make it work so that the alerts view covers the entire screen (including the navigation bar).
Here’s what I have done:
-
In the “Member Center” view controller, on viewDidLoad, I am creating a new view (my AlertView), changing it’s frame to show up at the bottom and then adding it as a subview to current view:
CGFloat alertBarHeight = 25; CGRect frame = self.view.frame; frame.origin.y = frame.size.height - alertBarHeight; AlertsView *av = [[AlertsView alloc] initWithFrame:frame withController:self height:alertBarHeight]; // Its a custom init method that just stores a reference to the invoking controller [self.view addSubview:av]; -
My show/hide code is in AlertsView.m and looks like this:
- (void) showOrHideAlerts:(id)sender { if (self.isOpen) { // Close the alerts view [UIView animateWithDuration:0.4 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ CGRect frame = self.frame; frame.origin.y = self.invokingController.view.frame.size.height - self.barHeight; self.frame = frame; } completion:^(BOOL finished) { self.isOpen = NO; }]; } else { // Show the alerts view [UIView animateWithDuration:0.4 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ CGRect frame = self.frame; frame.origin.y = 0;// - [self.invokingController.navigationController navigationBar].frame.size.height; //frame.origin.y = 20; self.frame = frame; } completion:^(BOOL finished) { self.isOpen = YES; }]; } }
I feel that I am not implementing it correctly. Please guide me on what’s the best way to implement such a feature.
Add your alert view to navigation controller view as below and not in the current view: