开发者

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:

  1. Create a custom view that can be initiated with a text to be displayed.
  2. 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.
  3. 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.
  4. Set the frame of the view to the invisibleFrame CGRect.
  5. 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];
                         }];
    
  6. Create a method that will slide out the view (after a certain time, using an animation block with delay).

  7. 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 ;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜