Я хочу использовать анимацию для просмотра изображений с помощью UIanimationtransitioncurl вправо или влево.Является ли это возможным? - PullRequest
0 голосов
/ 24 января 2011

Я хочу анимировать мою фотогалерею, как страницы книги. Есть ли способ, с помощью которого я могу использовать UIanimationtransitioncurl в левой или правой части?

Это код, который вы мне предложили. Я выполнил распределение по методу viewdidload.

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];

// Я поместил его в событие действия кнопки.

- (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];
}

1 Ответ

1 голос
/ 24 января 2011

Да, вы можете. Это код, который я использую для этого,

    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.

А затем применить переход к родительскому представлению,

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

Он будет скручиваться влево или вправо, когда вы скручиваетесь вверх и вниз.

** Обратите внимание, что вам нужно будет поиграть со смещением видов, чтобы оно отображалось правильно, но это прекрасно работает для меня.

...