Animation encapsulated by uiview

Source: Internet
Author: User

//
// Mjviewcontroller. m
// 10-uiview encapsulated Animation
//
// Created by Apple on 14-4-21.
// Copyright (c) 2014 itcast. All rights reserved.
//

# Import "mjviewcontroller. H"

@ Interface mjviewcontroller ()
@ Property (weak, nonatomic) iboutlet uiview * myview;
@ Property (weak, nonatomic) iboutlet uiimageview * iconview;
@ Property (nonatomic, assign) int index;
@ End

@ Implementation mjviewcontroller

-(Void) touchesbegan :( nsset *) touches withevent :( uievent *) event
{
Self. Index ++;
If (self. Index = 3 ){
Self. Index = 0;
}

Nsstring * filename = [nsstring stringwithformat: @ "mongod.jpg", self. index + 1];
Self. iconview. Image = [uiimage imagenamed: Filename];

// Execute the transition animation for the current view
[Uiview transitionwithview: Self. View Duration: 1.0 options: uiviewanimationoptiontransitionflipfromtop animations: Nil completion: Nil];
}

/**
* Simple animation provided by uiview
*/
-(Void) testviewsimpleanim
{
[Uiview beginanimations: Nil context: Nil];
// After the animation is executed, the animation stop method of self is automatically called.
// [Uiview setanimationdelegate: Self]; // sets the animation proxy
// [Uiview setanimationdidstopselector: @ selector (animatestop)]; // After the animation is executed, the current controller's animatestop will be called
Self. myview. Center = cgpointmake (200,300 );
[Uiview commitanimations];

// Block Animation
[Uiview animatewithduration: 1.0 animations: ^ {
Self. myview. Center = cgpointmake (200,300 );
} Completion: ^ (bool finished) {// After the animation is executed, it will be in completion.

}];
}

/**
* Layer Animation
*/
-(Void) testlayeranim
{
Cabasicanimation * anim = [cabasicanimation animation];
Anim. keypath = @ "position ";
Anim. tovalue = [nsvalue valuewithcgpoint: cgpointmake (0, 0)];
Anim. duration= 2.0;

Anim. removedoncompletion = no;
Anim. fillmode = kcafillmodeforwards;
Anim. Delegate = self;

// Layer animation is an illusion. During the animation execution, the position attribute of the layer has never changed.
[Self. myview. layer addanimation: anim forkey: Nil];

// Self. myview. layer. Position = cgpointmake (0, 0)
}

-(Void) animationdidstop :( caanimation *) anim finished :( bool) Flag
{
Nslog (@ "% @", nsstringfromcgpoint (self. myview. layer. Position ));
}

@ End

Animation encapsulated by uiview

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.