IOS animation to the right pull drawer 3D effect _ios

Source: Internet
Author: User

First of all we ignore the 3D effect, the first thing to do is a right pull drawer effect.

General ideas:

1. Create a Containerviewcontroller container controller, then the left side of the selection menu Sidemenuviewcontroller, and the right side is responsible for displaying the content of the Mainviewcontroller Added to the Containerviewcontroller.

2. Add a gesture monitor to the container controller Containerviewcontroller to complete the drawer effect by modifying the offset.

3. Set Anchorpoint, add 3D effect to view of left Sidemenuviewcontroller and Picture button in upper left corner.

If you want to know the details, please see the code, we have the core part of the following:

Add gesture monitoring to the containerviewcontroller, and then what to do with the Listening method:

 Func handlegesture (Recognizer:uipangesturerecognizer) {Let translation = Recognizer.translationinview (recognizer.v iew!.

    superview!) (isopening? 1.0: -1.0) isopening is a bool value that indicates that the Var progress is turned on or off = Translation.x/menuwidth * (isopening? 1.0:-1.) 0//Guaranteed between 0~1 progress = min (max (progress, 0), 1.0) switch Recognizer.state {case. Began:let IsOpen = Mainvc.view.frame.origin.x/menuwidth isopening = IsOpen = 1.0?
      False:true//To add a cache for the layer effect, which is to avoid the sawtooth SideMenuVC.view.layer.shouldRasterize = true when rotating; Set the scope of the render SideMenuVC.view.layer.rasterizationScale = Uiscreen.mainscreen (). Scale case.

    Changed://Core code: Adjust the position of the view in the container 3D effect and transparency and the flip effect of the upper left corner button Settopercent (isopening? Progress: (1.0-progress)) Case. Ended:fallthrough case. Cancelled:fallthrough case. Failed://Paging effect var targetprogress:cgfloat if (isopening) {targetprogress = Progress < 0.5 ? 0.0:1
      }else {targetprogress = progress < 0.5 1:0.0}//Set the effect of SIDEMENUVC view in failed state
        Uiview.animatewithduration (Animationtime, animations: {()-> Void in Self.settopercent (targetprogress) }, Completion: {(_)-> Void in//Remember to turn off layer cache rendering Self.sideMenuVC.view.layer.shouldRasterize = Fals e}) Default:break}}

Settings in the Settopercent method:

  Func settopercent (percent:cgfloat) {

    //adjust Mainvc.view position
    mainvc.view.frame.origin.x = menuwidth * CGFloat ( percent)
    //Set 3D effect and transparency
    SideMenuVC.view.layer.transform = menutransformforpercent (percent)
    SideMenuVC.view.alpha = CGFloat (max (0.2, percent))

    //Flip of top left button set let
    MAINVC = (MAINVC as! Uinavigationcontroller). Viewcontrollers.first as? Mainviewcontroller
    if let Menubutton = MAINVC? Menubutton {
      menuButton.imageView.layer.transform = buttontransformforpercent (percent)
    }
  }

The core code for the 3D effect:

//Add a 3D effect to percent func menutransformforpercent (percent:cgfloat)-> catransform3d {VA R identify = catransform3didentity//M34 is responsible for the z-axis direction translation (move), m34= -1/d, the default value is 0, D the smaller the perspective effect is more obvious, this side of the 1000 depending on the situation adjusted identif Y.M34 = -1.0/1000 Let remainingpercent = 1.0-percent let angle = remainingpercent * CGFloat (-m_pi_2)//back 3 numbers x y z Let rotationtransform = catransform3drotate (Identify, angle, 0.0, 1.0, 0.0)//convert value to a matrix let transl Ationtransform = catransform3dmaketranslation (menuwidth * percent, 0, 0)//combine the above two to return Catransform3dconc  At (Rotationtransform, translationtransform)}//Add a 3D effect to the button func buttontransformforpercent (percent:cgfloat) -> Catransform3d {var identity = catransform3didentity Identity.m34 = -1.0/1000 let angle = percent * C Gfloat (-M_PI) Let Rotationtransform = Catransform3drotate (identity, Angle, 1.0, 1.0, 0.0) return rotationtransfor m} 

The above is the iOS in the right drawer 3D effect of the implementation of the example code, the effect is not very good, I believe that the development of iOS small partners through the above example code can achieve this animation oh.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.