For iphone development, how to flip UIImageView?

I want to flip imageView (left / right), but I can not find the UIView (or UIImageView) method for this? any idea?

thanks!

+3
source share
4 answers

I think the only thing you are looking for is:

Uiview's

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

and

UIViewAnimationTransitionFlipFromLeft,
UIViewAnimationTransitionFlipFromRight,

These animation transitions can only be used in an animation block. The transition is specified in the container view, and then the old view is replaced for the new view, and then the animation is performed.

how

CGContextRef context = UIGraphicsGetCurrentContext();

[UIView beginAnimations:nil context:context];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:yourContainerView cache:YES];
[yourContainerView exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
[UIView commitAnimations];
+16
source

Put your UIIMageView in a UIView and use this code (from the sample application utility project)

- (void)loadFlipsideViewController {

    FlipsideViewController *viewController = [[FlipsideViewController alloc] initWithNibName:@"FlipsideView" bundle:nil];
    self.flipsideViewController = viewController;
    [viewController release];

    // Set up the navigation bar
    UINavigationBar *aNavigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
    aNavigationBar.barStyle = UIBarStyleBlackOpaque;
    self.flipsideNavigationBar = aNavigationBar;
    [aNavigationBar release];

    UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(toggleView)];
    UINavigationItem *navigationItem = [[UINavigationItem alloc] initWithTitle:@"Test123"];
    navigationItem.rightBarButtonItem = buttonItem;
    [flipsideNavigationBar pushNavigationItem:navigationItem animated:NO];
    [navigationItem release];
    [buttonItem release];
}


- (IBAction)toggleView {    
    /*
     This method is called when the info or Done button is pressed.
     It flips the displayed view from the main view to the flipside view and vice-versa.
     */
    if (flipsideViewController == nil) {
        [self loadFlipsideViewController];
    }

    UIView *mainView = mainViewController.view;
    UIView *flipsideView = flipsideViewController.view;

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1];
    [UIView setAnimationTransition:([mainView superview] ? UIViewAnimationTransitionFlipFromRight : UIViewAnimationTransitionFlipFromLeft) forView:self.view cache:YES];

    if ([mainView superview] != nil) {
        [flipsideViewController viewWillAppear:YES];
        [mainViewController viewWillDisappear:YES];
        [mainView removeFromSuperview];
        [infoButton removeFromSuperview];
        [self.view addSubview:flipsideView];
        [self.view insertSubview:flipsideNavigationBar aboveSubview:flipsideView];
        [mainViewController viewDidDisappear:YES];
        [flipsideViewController viewDidAppear:YES];

    } else {
        [mainViewController viewWillAppear:YES];
        [flipsideViewController viewWillDisappear:YES];
        [flipsideView removeFromSuperview];
        [flipsideNavigationBar removeFromSuperview];
        [self.view addSubview:mainView];
        [self.view insertSubview:infoButton aboveSubview:mainViewController.view];
        [flipsideViewController viewDidDisappear:YES];
        [mainViewController viewDidAppear:YES];
    }
    [UIView commitAnimations];
}
0
source

mainView flipToView - imageViews, containerView - UIView.

, View ImageView .

- (void)curlAction:(id)sender
{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.75];

    [UIView setAnimationTransition:([mainView superview] ?                          UIViewAnimationTransitionCurlUp : UIViewAnimationTransitionCurlDown)forView:containerView cache:YES];
    if ([flipToView superview])
    {
        [flipToView removeFromSuperview];
        [containerView addSubview:mainView];
    }
    else
    {
        [mainView removeFromSuperview];
        [containerView addSubview:flipToView];
    }

    [UIView commitAnimations];
}

- (void)flipAction:(id)sender
{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.75];

    [UIView setAnimationTransition:([mainView superview] ?
                                        UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight)
                                        forView:containerView cache:YES];
    if ([flipToView superview])
    {
        [flipToView removeFromSuperview];
        [containerView addSubview:mainView];
    }
    else
    {
        [mainView removeFromSuperview];
        [containerView addSubview:flipToView];
    }

    [UIView commitAnimations];
}

0

repo, ! , : / 90 /.

0

All Articles