I want to use animation to imageview using UIanimationtransitioncurl right or left. Is it possible?
Asked Answered
H

1

0

I want to animate my photo gallery like the pages of the book. Is there any method with that I can use UIanimationtransitioncurl in either the left or right side?

This is the code as you have suggested to me. I have done the allocation on the viewdidload method.

self.title = @"TransitionsTitle";

// Create the container view which we will use for transition animation (centered horizontally).
CGRect frame = CGRectMake(round((self.view.bounds.size.width - kImageWidth) / 2.0),
                                                    kTopPlacement, kImageWidth, kImageHeight);
self.containerView = [[[UIView alloc] initWithFrame:frame] autorelease];
[self.view addSubview:self.containerView];

// The container view can represent the images for accessibility.
[self.containerView setIsAccessibilityElement:YES];
[self.containerView setAccessibilityLabel:NSLocalizedString(@"ImagesTitle", @"")];

// Create the initial image view.
frame = CGRectMake(0.0, 0.0, kImageWidth, kImageHeight);
self.mainView = [[[UIImageView alloc] initWithFrame:frame] autorelease];
self.mainView.image = [UIImage imageNamed:@"scene1.jpg"];
[self.containerView addSubview:self.mainView];

// Create the alternate image view (to transition between).
CGRect imageFrame = CGRectMake(0.0, 0.0, kImageWidth, kImageHeight);
self.flipToView = [[[UIImageView alloc] initWithFrame:imageFrame] autorelease];
self.flipToView.image = [UIImage imageNamed:@"scene2.jpg"];
CGAffineTransform rotate=CGAffineTransformMakeRotation(3.14/2);
[containerView setTransform:rotate];
[self.view addSubview:containerView];
rotate=CGAffineTransformMakeRotation(-3.14/2);
[mainView setTransform:rotate];
[self.containerView addSubview:mainView];
[self.mainView addSubview:flipToView];

// I have put it on button action event.

- (IBAction)flipAction:(id)sender{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:4];
    [UIView setAnimationTransition:([self.mainView superview] ?
                                        UIViewAnimationTransitionCurlDown : UIViewAnimationTransitionCurlDown)
                                        forView:self.containerView cache:YES];
    if ([flipToView superview])
    {
        [self.flipToView removeFromSuperview];
        [self.containerView addSubview:mainView];
    }
    else
    {
        [self.mainView removeFromSuperview];
        [self.containerView addSubview:flipToView];
    }
    [UIView commitAnimations];
}
Hightension answered 24/1, 2011 at 9:37 Comment(3)
Hi, you should paste the first part of the code (the rotation code) from my first answer in the viewDidLoad method and not in the action itself.Valorie
hi i have done it still not showing the result you was talking about the setting offset can you help me that how does it effect to animation?Hightension
What is "UIanimationtransitioncurl"?Carbineer
V
1

Yes, you can. This is the code I use for that,

    self.containerViewParent = [[[UIView alloc] initWithFrame:CGRectMake(what ever you want)] autorelease]; //Create a container parent for the container view.

    self.containerView = [[[UIView alloc] initWithFrame:GRectMake(what ever you want)] autorelease]; //Create a container view for the view you wish to display.

    CGAffineTransform rotate = CGAffineTransformMakeRotation(-3.14/2);
    [containerViewParent setTransform:rotate]; //Rotate the containerViewParent.

    [self.view addSubview:containerViewParent];//Add it to the main view.

    rotate = CGAffineTransformMakeRotation(3.14/2);
    [containerView setTransform:rotate];//Rotate the containerView.

    [self.containerViewParent addSubview:containerView]; //Add it to the self.containerViewParent.
    [self.containerView addSubview:viewToDisplay]; //Add the view you want to display.

And then apply the transition to the parent view,

    [UIView beginAnimations:@"page transition" context:nil];
    [UIView setAnimationDuration:2.0];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.containerView cache:YES];
    [UIView commitAnimations];

It will curl to the left or the right when you curl up and down.

**Note that you will need to play with the offset of the views to make it display correctly, but it works great for me.

Valorie answered 24/1, 2011 at 9:56 Comment(6)
THANX FOR ANSWER BUDDY BUT IT SHOW THE SAME RESULT AS CURL UP AND DOWN CAN TELL ME LITTLE BIT MORE THANX IN ADVANCEHightension
can you post your code? it is working in one of my apps with the code above.Valorie
i have posted the code i call flipaction method on the button action event hope you don't get trouble on reading code thank you very muchHightension
Hey Buddy It Is Working Properly I had made mistake between to container view THANK YOU VERY MUCHHightension
you welcome. approving the answer (the checkmark green mark) will help you and me get answers quickly. your approving rate is visible to users and low rate will harm your chances to get answers.Valorie
@Freezing Fire: WHAT IS UP WITH THE CAPITALIZATION? :)Killerdiller

© 2022 - 2024 — McMap. All rights reserved.