uiview


若是想調用某個類的某個方法能夠寫成這樣,這個方法來自NSObject類javascript


C代碼 收藏代碼
  1. performSelector:  css

  2. performSelector:withObject:  html

  3. performSelector:withObject:withObject:  java

實際調用jquery


C代碼 收藏代碼
  1. [self performSelector:@selector(displayViews) withObject:nil afterDelay:1.0f];  spring

 有三個方法分別是數據庫


C代碼 收藏代碼
  1. //父視圖 windows

  2. [self.view superview]  服務器

  3. //全部子視圖app

  4. [self.view subviews]  

  5. //自身的window

  6. self.view.window  

循環一個視圖下面全部視圖的方法


C代碼 收藏代碼
  1. NSArray *allSubviews(UIView *aView)  

  2. {  

  3.    NSArray *results = [aView subviews];  

  4. for (UIView *eachView in [aView subviews])  

  5.    {  

  6.        NSArray *riz = allSubviews(eachView);  

  7. if (riz) {  

  8.            results = [results arrayByAddingObjectsFromArray:riz];  

  9.        }  

  10.    }  

  11. return results;  

  12. }  

循環返回一個APPLICATION裏面全部的VIEW


C代碼 收藏代碼
  1. // Return all views throughout the application

  2. NSArray *allApplicationViews()  

  3. {  

  4.    NSArray *results = [[UIApplication sharedApplication] windows];  

  5. for (UIWindow *window in [[UIApplication sharedApplication] windows])  

  6.    {  

  7.        NSArray *riz = allSubviews(window);  

  8. if (riz) results = [results arrayByAddingObjectsFromArray: riz];  

  9.    }  

  10. return results;  

  11. }  

找出全部的父視圖


C代碼 收藏代碼
  1. // Return an array of parent views from the window down to the view

  2. NSArray *pathToView(UIView *aView)  

  3. {  

  4.    NSMutableArray *array = [NSMutableArray arrayWithObject:aView];  

  5.    UIView *view = aView;  

  6.    UIWindow *window = aView.window;  

  7. while (view != window)  

  8.    {  

  9.        view = [view superview];  

  10.        [array insertObject:view atIndex:0];  

  11.    }  

  12. return array;  

  13. }  

UIView提供了大量管理視圖的方法


C代碼 收藏代碼
  1. //加一個視圖到一個視圖裏面

  2. addSubview:  

  3. //將一個視圖移到前面

  4. bringSubviewToFront:  

  5. //將一個視圖推送到背後

  6. sendSubviewToBack:  

  7. //把視圖移除

  8. removeFromSuperview  

  9. //插入視圖 並指定索引

  10. insertSubview:atIndex:  

  11. //插入視圖在某個視圖之上

  12. insertSubview:aboveSubview:  

  13. //插入視圖在某個視圖之下

  14. insertSubview:belowSubview:  

  15. //交換兩個位置索引的視圖

  16. exchangeSubviewAtIndex:withSubviewAtIndex:  

視圖回調


C代碼 收藏代碼
  1. //當加入視圖完成後調用

  2. (void)didAddSubview:(UIView *)subview  

  3. //當視圖移動完成後調用

  4. (void)didMoveToSuperview  

  5. //當視圖移動到新的WINDOW後調用

  6. (void)didMoveToWindow  

  7. //在刪除視圖以後調用

  8. (void)willRemoveSubview:(UIView *)subview  

  9. //當移動視圖以前調用

  10. (void)didMoveToSuperview:(UIView *)subview  

  11. //當視圖移動到WINDOW以前調用

  12. (void)didMoveToWindow  

給UIView設置標記和檢索視圖


C代碼 收藏代碼
  1. myview.tag = 1001;  

  2. [self.view viewWithTag:1001];  

  3. (UILable *)[self.view.window viewWithTag:1001];  

視圖的幾何特徵


C代碼 收藏代碼
  1. //框架

  2. struct CGPoint {  

  3.  CGFloat x;  

  4.  CGFloat y;  

  5. };  

  6. typedefstruct CGPoint CGPoint;  

  7. /* Sizes. */

  8. struct CGSize {  

  9.  CGFloat width;  

  10.  CGFloat height;  

  11. };  

  12. typedefstruct CGSize CGSize;  

  13. struct CGRect {  

  14.  CGPoint origin;  

  15.  CGSize size;  

  16. };  

  17. typedefstruct CGRect CGRect;  

  18. CGRect rect = CGRectMake(0,0,320,480);  

  19. UIView *view = [[UIView allow]initWithFrame:rect];  

  20. //將String轉成CGPoint 如 @」{3.0,2.5}」    {x,y}

  21. CGPoint CGPointFromString (  

  22.   NSString *string  

  23. );  

  24. //將String轉成CGRect  @」{{3,2},{4,5}}」  {{x,y},{w, h}}

  25. CGRect CGRectFromString (  

  26.   NSString *string  

  27. );  

  28. //將String轉成CGSize @」{3.0,2.5}」 {w, h}

  29. CGSize CGSizeFromString (  

  30.   NSString *string  

  31. );  

  32. //CGPoint轉成NSString

  33. NSString * NSStringFromCGPoint (  

  34.   CGPoint point  

  35. );  

  36. //CGRect轉成NSString

  37. NSString * NSStringFromCGRect (  

  38.   CGRect rect  

  39. );  

  40. //CGSize轉成NSString

  41. NSString * NSStringFromCGSize (  

  42.   CGSize size  

  43. );  

  44. //對一個CGRect進行修改 以這個的中心來修改 正數表示更小(縮小) 負數表示更大(放大)

  45. CGRect CGRectInset (  

  46.   CGRect rect,  

  47.   CGFloat dx,  

  48.   CGFloat dy  

  49. );  

  50. //判斷兩個矩形是否相交

  51. bool CGRectIntersectsRect (  

  52.   CGRect rect1,  

  53.   CGRect rect2  

  54. );  

  55. //初始爲0的

  56. const CGPoint CGPointZero;  

  57. const CGRect CGRectZero;  

  58. const CGSize CGSizeZero;  

  59. //建立CGPoint

  60. CGPoint CGPointMake (  

  61.   CGFloat x,  

  62.   CGFloat y  

  63. );  

  64. //建立CGRect

  65. CGRect CGRectMake (  

  66.   CGFloat x,  

  67.   CGFloat y,  

  68.   CGFloat width,  

  69.   CGFloat height  

  70. );  

  71. //建立CGSize

  72. CGSize CGSizeMake (  

  73.   CGFloat width,  

  74.   CGFloat height  

  75. );  

仿射變換


C代碼 收藏代碼
  1. CGAffineTransform form = CGAffineTransformMakeRotation(PI);  

  2. myview.transform = form;  

如想復原


C代碼 收藏代碼
  1. myview.transform = CGAffineTransformIdentity;  

直接設置視圖的中心


C代碼 收藏代碼
  1. myview.center = CGPointMake(100,200);  

中心


C代碼 收藏代碼
  1. CGRectGetMinX  

  2. CGRectGetMinY  

  3. //X的中間值

  4. CGRectGetMidX  

  5. //Y的中間值

  6. CGRectGetMidY  

  7. CGRectGetMaxX  

  8. CGRectGetMaxY  

 定時器


C代碼 收藏代碼
  1. NSTime *timer = [NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector:@selector(move:) userInfo:nil repeats:YES];  

 定義視圖邊界

C代碼 收藏代碼
  1. typedefstruct UIEdgeInsets {  

  2.    CGFloat top, left, bottom, right;  // specify amount to inset (positive) for each of the edges. values can be negative to 'outset'

  3. } UIEdgeInsets;  

  4. //eg

  5. UIEdgeInsets insets = UIEdgeInsetsMake(5, 5, 5, 5);  

  6. CGRect innerRect = UIEdgeInsetsInsetRect([aView bounds], insets);  

  7. CGRect subRect = CGRectInset(innerRect, self.frame.size.width / 2.0f, self.frame.size.height / 2.0f);  

仿射變換補充

//建立CGAffineTransform

C代碼 收藏代碼
  1. //angle 在0-2*PI之間比較好  旋轉

  2. CGAffineTransform transform = CGAffineTransformMakeRotation(angle);  

  3. //縮放

  4. CGAffineTransform transform = CGAffineTransformMakeScale(0.5f,0.5f);  

  5. //改變位置的

  6. CGAffineTransform transform = CGAffineTransformMakeTranslation(50,60);  

  7. //修改CGAffineTransform

  8. //修改 縮放

  9. CGAffineTransform scaled = CGAffineTransformScale(transform, degree, degree);  

  10. //修改 位置

  11. CGAffineTransform transform = CGAffineTransformTranslate(  

  12.   CGAffineTransform t,  

  13.   CGFloat tx,  

  14.   CGFloat ty  

  15. );  

  16. //修改角度

  17. CGAffineTransform transform = CGAffineTransformRotate (  

  18.   CGAffineTransform t,  

  19.   CGFloat angle  

  20. );  

  21. //最後設置到VIEW

  22. [self.view setTransform:scaled];  

創建UIView動畫塊

  //首先創建CGContextRef

C代碼 收藏代碼
  1. CGContextRef context = UIGraphicsGetCurrentContext();  

  2. //標記動畫開始

  3. [UIView beginAnimations:nil context:context];  

  4. //定義動畫加速或減速的方式

  5. [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];  

  6. //定義動畫的時長 1秒

  7. [UIView setAnimationDuration:1.0];  

  8. //中間處理 位置變化,大小變化,旋轉,等等的

  9. [[self.view viewWithTag:999] setAlpha:1.0f];  

  10. //標誌動畫塊結束

  11. [UIView commitAnimations];  

  12. //還能夠設置回調

  13. [UIView setAnimationDelegate:self];  

  14. //設置回調調用的方法

  15. [UIView setAnimationDidStopSelector:@selector(animationFinished:)];  

 視圖翻轉


C代碼 收藏代碼
  1. UIView *whiteBackdrop = [self.view viewWithTag:100];  

  2. // Choose left or right flip 選擇左或右翻轉

  3. if ([(UISegmentedControl *)self.navigationItem.titleView selectedSegmentIndex]){  

  4. [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:whiteBackdrop cache:YES];  

  5. }else{  

  6. [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:whiteBackdrop cache:YES];  

  7. }  

  8.    NSInteger purple = [[whiteBackdrop subviews] indexOfObject:[whiteBackdrop viewWithTag:999]];  

  9.    NSInteger maroon = [[whiteBackdrop subviews] indexOfObject:[whiteBackdrop viewWithTag:998]];  

  10. //交換視圖

  11.    [whiteBackdrop exchangeSubviewAtIndex:purple withSubviewAtIndex:maroon];  

  12. //還有上翻和下翻兩種 以下

  13. typedefenum {  

  14. //沒有任何效果

  15.    UIViewAnimationTransitionNone,  

  16.    UIViewAnimationTransitionFlipFromLeft,  

  17.    UIViewAnimationTransitionFlipFromRight,  

  18.    UIViewAnimationTransitionCurlUp,  

  19.    UIViewAnimationTransitionCurlDown,  

  20. } UIViewAnimationTransition;  

 使用QuartzCore作動畫


C代碼 收藏代碼
  1. //建立CATransition

  2. CATransition *animation = [CATransition animation];  

  3. //設置代理

  4. animation.delegate = self;  

  5. //設置動畫過渡的時間

  6. animation.duration = 4.0f;  

  7. //定義動畫加速或減速的方式

  8. animation.timingFunction = UIViewAnimationCurveEaseInOut;  

  9. //animation.type 表示設置過渡的種類 如 Fade,MoveIn,Push,Reveal

  10. switch ([(UISegmentedControl *)self.navigationItem.titleView selectedSegmentIndex]) {  

  11. case 0:  

  12.            animation.type = kCATransitionFade;  

  13. break;  

  14. case 1:  

  15.            animation.type = kCATransitionMoveIn;  

  16. break;  

  17. case 2:  

  18.            animation.type = kCATransitionPush;  

  19. break;  

  20. case 3:  

  21.            animation.type = kCATransitionReveal;  

  22. default:  

  23. break;  

  24.    }  

  25. //設置漸變的方向,上下左右

  26. if (isLeft)  

  27.        animation.subtype = kCATransitionFromRight;  

  28. else

  29.        animation.subtype = kCATransitionFromLeft;  

  30. // Perform the animation

  31.    UIView *whitebg = [self.view viewWithTag:10];  

  32.    NSInteger purple = [[whitebg subviews] indexOfObject:[whitebg viewWithTag:99]];  

  33.    NSInteger white = [[whitebg subviews] indexOfObject:[whitebg viewWithTag:100]];  

  34.    [whitebg exchangeSubviewAtIndex:purple withSubviewAtIndex:white];  

  35.    [[whitebg layer] addAnimation:animation forKey:@"animation"];  

animation.type還能夠用如下的賦值


C代碼 收藏代碼
  1. switch (theButton.tag) {    

  2. case 0:    

  3.            animation.type = @"cube";    

  4. break;    

  5. case 1:    

  6.            animation.type = @"suckEffect";    

  7. break;    

  8. case 2:    

  9.            animation.type = @"oglFlip";    

  10. break;    

  11. case 3:    

  12.            animation.type = @"rippleEffect";    

  13. break;    

  14. case 4:    

  15.            animation.type = @"pageCurl";    

  16. break;    

  17. case 5:    

  18.            animation.type = @"pageUnCurl";    

  19. break;    

  20. case 6:    

  21.            animation.type = @"cameraIrisHollowOpen ";    

  22. break;    

  23. case 7:    

  24.            animation.type = @"cameraIrisHollowClose ";    

  25. break;    

  26. default:    

  27. break;    

  28.    }    

 上面這個是轉自這裏的http://2015.iteye.com/blog/1122130

休眠一下


C代碼 收藏代碼
  1. [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0f]];  

一個簡單的經過圖片作的動畫


C代碼 收藏代碼
  1. // Load butterfly p_w_picpaths

  2. NSMutableArray *bflies = [NSMutableArray array];  

  3. for (int i = 1; i <= 17; i++){  

  4.    [bflies addObject:[UIImage p_w_picpathWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"bf_%d", i] ofType:@"png"]]];  

  5. }  

  6. UIImageView *butterflyView = [[UIImageView alloc] initWithFrame:CGRectMake(40.0f, 300.0f, 60.0f, 60.0f)];  

  7. butterflyView.tag = 300;  

  8. //設置動畫的圖片

  9. butterflyView.animationImages = bflies;  

  10. //設置時間

  11. butterflyView.animationDuration = 0.75f;  

  12. [self.view addSubview:butterflyView];  

  13. //開始動畫

  14. [butterflyView startAnimating];  

  15. [butterflyView release];  


預留

預留

預留


評論
langhua9527
  • 瀏覽: 179096 次

  • 性別: Icon_minigender_1

  • 來自: 昆明

  • offline.gif

社區版塊
存檔分類
最新評論
相關文章
相關標籤/搜索