How do I create a page flip effect programmaticall

2020-06-27 05:56发布

问题:

I'm pretty sure I can create a page flip effect using a series of PNGs to simulate the animation but is there a way to do it programmatically? Tried googling it and looking at Apple sample code but didn't see anything addressing that particular animation.

回答1:

I'm assuming you mean for an iPhone, right?

From the Apple API docs for UIView:

+ (void)setAnimationTransition:(UIViewAnimationTransition)transition forView:(UIView *)view cache:(BOOL)cache

where UIViewAnimationTransition is defined as:

typedef enum {
   UIViewAnimationTransitionNone,
   UIViewAnimationTransitionFlipFromLeft,
   UIViewAnimationTransitionFlipFromRight
   UIViewAnimationTransitionCurlUp,
   UIViewAnimationTransitionCurlDown,
} UIViewAnimationTransition;

UIViewAnimationTransitionCurlUp is what you are looking for. See those docs for information on how to start, set, and commit animations to views as well.