简体   繁体   中英

How to slide UIView from side on top of current view (iPhone)

At the moment I have a view that contains an MKMapView. I also have a separate UIView (Made in IB) that I want to slide onto the existing view.

The way I want to do this is to slide the view from the left hand side, while at the same time reducing the size of the map view.

I also want the reverse to be possible, such that the view will slide off to the left and the map view will expand to fill the gap.

The only catch is that I want this to be a nice smooth animation. I know how to display the UIView on top and then resize the map view, however this appears quite clunky. I'm more after the effect you see when an iAd banner slides on and off the screen (but with the map view resizing at the same rate as the UIView moves on-screen).

Sorry if this is a simple thing to do, this is my first time working with animations.

Thanks in advance.

The simplest way is to use the UIView animation methods. Something like this:

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1.0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    slideInView.frame = CGRectMake(0,0,320,20);
    mapView.frame = CGRectMake(0,20,320,460);
    [UIView commitAnimations];

And the reverse is similar, but with different frame size.

This is i have done using UIView animation.You can change the frame size according to your need.

self.mapView.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: 350)


 slideInView.frame = CGRect(x: 0, y: -320, width: self.view.frame.size.width, height: 250)
      UIView.animate(withDuration: 1.0, delay: 0.1, options: [.curveEaseIn] , animations: {
           self.slideInView.frame = CGRect(x: 0, y: 64, width: self.view.frame.size.width, height: 250)
      })
      {(BOOL) in}

self.view.addSubview(slideInView)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM