IOSDevelopment InstanceViewImplementationAnimationThe effect is what we will introduce in this article.IosIn applications, you can often see a click button, a view gradually pops up, and a button, the view slowly scales back. ThisAnimationThe effects are often used in ios. The following is a small example I wrote. The interface effects are as follows:
The specific implementation process is as follows:
Create a project.
Use Interface Builder to add a button and a view to change the background color of the view.
Declare in the header file:
- # Import <UIKit/UIKit. h>
-
- @ Interface ipad_scrollViewViewController: UIViewController {
-
- IBOutlet UIButton * myButton;
- UILabel * tableView;
- IBOutlet UIView * myView;
- }
- @ Property (nonatomic, retain) UIButton * myButton;
- @ Property (nonatomic, retain) UIView * myView;
- -(IBAction) onClickButton :( id) sender;
- @ End
-
- Connect components in IB with related objects.
-
- Implementation Code:
-
- # Import "ipad_scrollViewViewController.h"
- @ Implementation ipad_scrollViewViewController
- @ Synthesize myButton, myView;
- -(Void) viewDidLoad {
- [Super viewDidLoad];
- }
- -(BOOL) shouldAutorotateToInterfaceOrientation :( UIInterfaceOrientation) interfaceOrientation {
- Return YES;
- }
-
- -(Void) didReceiveMemoryWarning {
- [Super didReceiveMemoryWarning];
- }
-
- -(Void) viewDidUnload {
- Self. myButton = nil;
- Self. myView = nil;
- }
- -(Void) dealloc {
- [Self. myView release];
- [Self. myButton release];
- [Super dealloc];
- }
- -(IBAction) onClickButton :( id) sender
- {
- CGContextRef context = UIGraphicsGetCurrentContext ();
- [UIView beginAnimations: @ "Curl" context: context];
- [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
- [UIView setAnimationDuration: 0.5];
- CGRect rect = [myView frame];
- CGRect rect1 = [myButton frame];
- If (rect. origin. x> 0 ){
- Rect. origin. x = 26366f-rect. size. width;
- Rect1.origin. x = 267.0f-rect. size. width;
- } Else {
- Rect. origin. x = 26366f;
- Rect1.origin. x = 267.0f;
- }
- [MyButton setFrame: rect1];
- [MyView setFrame: rect];
- [UIView commitAnimations];
- }
- @ End
Source code: http://easymorse-iphone.googlecode.com/svn/trunk/ipad.scrollView/
Although the above Code can move a view, one problem is that a view cannot be clicked if it is in the middle of the screen, from scratch and an animation that moves from one side to the other.
Summary:IOSDevelopment InstanceViewImplementationAnimationI hope this article will be helpful to you.