iOS imageView旋转


下面的gif是通过UIView的专场动画来实现的,请问一下,能不能通过UIImageView来实现这个效果?如果能实现,能不能给出一个demo,非常感谢~
图片描述

uiimageview ios objective-c

Mcドナルド 9 years, 8 months ago

晚一点给你吧

主角挚友丶 answered 9 years, 8 months ago

下载看吧,实现很简单, Demo在这里 RotatingAnimationDemo

按下按钮出发旋转,下面是实现:


 - (IBAction)onButtonTouch:(id)sender
{
    // 标记翻转状态
    self.isChanged = !self.isChanged;

    // 动画配置
    NSTimeInterval duration = 0.5;
    UIViewAnimationTransition transition = self.isChanged ? UIViewAnimationTransitionFlipFromRight : UIViewAnimationTransitionFlipFromLeft;

    // 提交动画
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:duration];
    [UIView setAnimationTransition:transition forView:self.imageView cache:NO];
    [UIView commitAnimations];

    // 动画进行到一半,设置图片
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(duration/2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^
    {
        self.imageView.image = [UIImage imageNamed: self.isChanged ? @"1" : @"2" ];
    });
}

凤凰院伦太郎 answered 9 years, 8 months ago

Your Answer