transform的图片缩放切换

简单无脑,直接上图:


图片缩放切换.gif

简单粗暴,直接上代码:


//加载3秒动画
[UIView animateWithDuration:3 animations:^{
//CGAffineTransformScale的X为 -1 时,图片左右反转
self.imgView.transform = CGAffineTransformScale(self.imgView.transform, -1, 1);
//CGAffineTransformScale的Y为 -1 时,图片上下反转
self.imgView.transform = CGAffineTransformScale(self.imgView.transform, 1, -1);
}];


//延迟 1.5 秒切换图片,并将图片转正
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//此处是图片的index,N为图片总数
if (self.index == N) {

            self.index = 0;
        }else{
            
            self.index++;
        }
        
        //切换图片
        self.imgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld",self.index]];
        //转正图片
        self.imgView.transform = CGAffineTransformScale(self.imgView.transform, -1, 1);
        self.imgView.transform = CGAffineTransformScale(self.imgView.transform, 1, -1);

});

偶然的尝试,感觉很神奇!!!!!

你可能感兴趣的:(transform的图片缩放切换)