


Detailed explanation of iOS Core Animation (5) CATransition_html/css_WEB-ITnose
Welcome to follow my iOS SDK detailed explanation column
Unknowingly, I have written the fifth article in the iOS animation series. Here, you can easily find the articles I wrote before. Four articles on animation.
Foreword: CATransition is a subclass of CAAnimation. Its main purpose is to define the transition animation of view reload. Using this integrated class, you can create great effects with just a few lines of code.
Effect 1
Animation
Core code,
CATransition * transition = [CATransition animation]; transition.type = kCATransitionFade; transition.duration = 1.0; [self.imageview.layer addAnimation:transition forKey:@"ToNext"]; self.imageview.image = nextImage;
Complete code
To first drag an imageview on the Storyboard , and drag outlet
@interface ViewController ()@property (weak, nonatomic) IBOutlet UIImageView *imageview;@property (assign,nonatomic)NSInteger currentIndex;@end@implementation ViewController-(NSArray *)imagesNamesArray{ return @[@"meidui1.jpg", @"meidui2.jpg"];}- (void)viewDidLoad { [super viewDidLoad]; UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(changeToNextImage)]; self.imageview.userInteractionEnabled = true; [self.imageview addGestureRecognizer:tap]; self.currentIndex = 0;}-(void)changeToNextImage{ self.currentIndex = (self.currentIndex + 1) % 2; NSString * imageName = [[self imagesNamesArray] objectAtIndex:self.currentIndex]; UIImage * nextImage = [UIImage imageNamed:imageName]; CATransition * transition = [CATransition animation]; transition.type = kCATransitionFade; transition.duration = 1.0; [self.imageview.layer addAnimation:transition forKey:@"ToNext"]; self.imageview.image = nextImage;}
Effect 2
Animation
Code
CATransition * transition = [CATransition animation]; transition.duration = 1.0;//动画间隔 transition.type = kCATransitionMoveIn;//主要种类,决定动画效果 transition.startProgress = 0.0;//开始 transition.endProgress = 1.0;//结束 transition.subtype = kCATransitionFromRight;//次要种类,决定动画方向 transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];//时间函数 [self.imageview.layer addAnimation:transition forKey:@"ToNext"]; self.imageview.image = nextImage;
There are four main types Species
NSString * const kCATransitionFade; //消退NSString * const kCATransitionMoveIn;//移入NSString * const kCATransitionPush;//pushNSString * const kCATransitionReveal;//退出
There are also four secondary species
NSString * const kCATransitionFromRight;NSString * const kCATransitionFromLeft;NSString * const kCATransitionFromTop;NSString * const kCATransitionFromBottom;

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

The article discusses the <iframe> tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...
