ios - iOS,随机滑动动画

原文 标签 ios animation random swipe

如何使用动画随机滑动。目前正在滑动,但是滑动时不会出现新图像。

- (void)swipeToTheRight:(UISwipeGestureRecognizer *)gestureRecognizer
{

        NSLog(@"Swiped to the right");
        [UIView animateWithDuration:0.5
                         animations:^{
                             [UIView beginAnimations:@"" context:nil];
                             [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
                             [UIView setAnimationDuration:1.0f];
                             [UIView commitAnimations];
                             [self.myImage setImage:[UIImage imageNamed:[images objectAtIndex:quoteIndex]]];
                             [self.view setNeedsUpdateConstraints];
                         }]; 
}


SwipeToTheLeft

- (void)swipeToTheLeft:(UISwipeGestureRecognizer *)gestureRecognizer
{

        NSLog(@"Swiped to the left");
        [UIView animateWithDuration:0.5
                         animations:^{
                             [UIView beginAnimations:@"" context:nil];
                             [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
                             [UIView setAnimationDuration:1.0f];
                             [UIView commitAnimations];
                             [self.myImage setImage:[UIImage imageNamed:[images objectAtIndex:quoteIndex]]];
                             [self.view setNeedsUpdateConstraints];
                         }];


@end

最佳答案

[UIView commitAnimations];行移动到块的末尾:

^{
     [UIView beginAnimations:@"" context:nil];
     [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
     [UIView setAnimationDuration:1.0f];

     [self.myImage setImage:[UIImage imageNamed:[images objectAtIndex:quoteIndex]]];
     [self.view setNeedsUpdateConstraints];
     [UIView commitAnimations];
 }

关于ios - iOS,随机滑动动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36841777/

相关文章:

javascript - javascript回调动画

java - Java:如何将Trident导入项目?

java - 为什么这段代码写/打印全 0.0 而不是不同的随机数?

algorithm - 在包含给定数字集的范围内随机选择一些数字的最快方法是什么?

ios - whatsapp 调用如何在 IOS 中工作?

iOS多模块应用

ios - Swift 同步网络请求

ios - 在 UIView 中加载 MKMapView

javascript - 在JavaScript中更改CSS动画

c++ - 为什么我的 mt19937 随机生成器给了我荒谬的结果? C++