IOS development instance View for animation effect

Source: Internet
Author: User

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:

 
 
  1. # Import <UIKit/UIKit. h>
  2.  
  3. @ Interface ipad_scrollViewViewController: UIViewController {
  4.  
  5. IBOutlet UIButton * myButton;
  6. UILabel * tableView;
  7. IBOutlet UIView * myView;
  8. }
  9. @ Property (nonatomic, retain) UIButton * myButton;
  10. @ Property (nonatomic, retain) UIView * myView;
  11. -(IBAction) onClickButton :( id) sender;
  12. @ End
  13.  
  14. Connect components in IB with related objects.
  15.  
  16. Implementation Code:
  17.  
  18. # Import "ipad_scrollViewViewController.h"
  19. @ Implementation ipad_scrollViewViewController
  20. @ Synthesize myButton, myView;
  21. -(Void) viewDidLoad {
  22. [Super viewDidLoad];
  23. }
  24. -(BOOL) shouldAutorotateToInterfaceOrientation :( UIInterfaceOrientation) interfaceOrientation {
  25. Return YES;
  26. }
  27.  
  28. -(Void) didReceiveMemoryWarning {
  29. [Super didReceiveMemoryWarning];
  30. }
  31.  
  32. -(Void) viewDidUnload {
  33. Self. myButton = nil;
  34. Self. myView = nil;
  35. }
  36. -(Void) dealloc {
  37. [Self. myView release];
  38. [Self. myButton release];
  39. [Super dealloc];
  40. }
  41. -(IBAction) onClickButton :( id) sender
  42. {
  43. CGContextRef context = UIGraphicsGetCurrentContext ();
  44. [UIView beginAnimations: @ "Curl" context: context];
  45. [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
  46. [UIView setAnimationDuration: 0.5];
  47. CGRect rect = [myView frame];
  48. CGRect rect1 = [myButton frame];
  49. If (rect. origin. x> 0 ){
  50. Rect. origin. x = 26366f-rect. size. width;
  51. Rect1.origin. x = 267.0f-rect. size. width;
  52. } Else {
  53. Rect. origin. x = 26366f;
  54. Rect1.origin. x = 267.0f;
  55. }
  56. [MyButton setFrame: rect1];
  57. [MyView setFrame: rect];
  58. [UIView commitAnimations];
  59. }
  60. @ 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.

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.