how to create an instagram like in-app popup alert
If you use Instagram app, it has a News tab menu in the bottom. If we received any news it will popup (like growl in mac) for 1-2 secs for addition information of new news that you received. It definitely not UIActionSheet nor UIAlertView.
Anyone know h开发者_StackOverflowow to code this?
This is heavily documented here:
How does the Instagram iPhone app implement a custom tab bar notification?
You could do the following:
- Create a custom view that can be initiated with a text to be displayed.
- In the init-function of said view, create a UILabel, set the text, resizeToFit the label, then resize the view so the label fits inside.
- Use two CGRects inside the view to store both the frame that the view will have, when it is visible and when it is invisible.
- Set the frame of the view to the invisibleFrame CGRect.
Create a method that will slide in the view:
[UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseOut animations:^{ self.frame = frameVisible; } completion:^(BOOL finished) { [self onSlideOutFinished]; }];
Create a method that will slide out the view (after a certain time, using an animation block with delay).
- Create a method inside the UIViewController responsible for displaying the view that will create new instances of your message view.
That's basically it. What you could do is have the UIViewController listen to NSNotifications that trigger the message view. You could also dynamically position the message views by storing them in an array and calculate the visible frame of new message views according to the frames of the currently visible, other message views.
I hope that was somewhat understandable ;)
精彩评论