UIView vertical flip animation

后端 未结 8 763
温柔的废话
温柔的废话 2020-11-30 17:09

I have an iOS UIView with UIViewAnimationTransitionFlipFromRight. I need it to flip vertically though. The page curl transition won\'t cut it. I assume this wil

8条回答
  •  执笔经年
    2020-11-30 17:52

    The code from Brenton didn't work for me so I did a little more digging through the apple docs and found this piece of code for an horizontal flip:

    - (IBAction)toggleMainViews:(id)sender {
        [UIView transitionFromView:(displayingPrimary ? primaryView : secondaryView)
                            toView:(displayingPrimary ? secondaryView : primaryView)
                          duration:1.0
                           options:(displayingPrimary ? 
                                        UIViewAnimationOptionTransitionFlipFromRight :
                                        UIViewAnimationOptionTransitionFlipFromLeft)
                        completion:^(BOOL finished) {
                                       if (finished) {
                                           displayingPrimary = !displayingPrimary;
                                       }
                                  }
        ];
    }
    

    You can do a vertical flip by changing the options from UIViewAnimationOptionTransitionFlipFromRight : UIViewAnimationOptionTransitionFlipFromLeft to UIViewAnimationOptionTransitionFlipFromTop : UIViewAnimationOptionTransitionFlipFromBottom.

    Worked like a charm.

提交回复
热议问题