IOS 4.2: Отразить изображение, используя анимацию блока
У меня была эта часть кода в моем приложении:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:imgView cache:YES];
imgView.image = img2;
[UIView commitAnimations];
Но использование этого метода не рекомендуется в iOS 4.0 и более поздних версиях, и я должен использовать transitionWithView:duration:options:animations:completion:
Я не могу заставить это работать правильно. Может кто-нибудь мне помочь?
спасибо!
Ответы
Ответ 1
[UIView transitionWithView:imgView // use the forView: argument
duration:1 // use the setAnimationDuration: argument
options:UIViewAnimationOptionTransitionFlipFromLeft
// check UIViewAnimationOptions for what options you can use
animations:^{ // put the animation block here
imgView.image = img2;
}
completion:NULL]; // nothing to do after animation ends.
Ответ 2
Я сделал эту функцию на основе вашего кода:
- (void)flipCurrentView:(UIView*)oldView withNewView:(UIView*)newView reverse:(BOOL)reverse
{
newView.alpha = 0;
[UIView transitionWithView:newView
duration:1
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
oldView.alpha = 0;
newView.alpha = 1;
}
completion:^(BOOL finished){
if(reverse){
[self flipCurrentView:newView withNewView:oldView reverse:NO];
}
finished = YES;
}];
}