久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

IOS開發(fā)之UIView總結(jié)

 panny_92 2014-12-06

 如果想調(diào)用某個(gè)類的某個(gè)方法可以寫成這樣,這個(gè)方法來自NSObject類

 

C代碼  收藏代碼
  1. performSelector:  
  2. performSelector:withObject:  
  3. performSelector:withObject:withObject:  

 實(shí)際調(diào)用

 

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

  有三個(gè)方法分別是

 

C代碼  收藏代碼
  1. //父視圖   
  2. [self.view superview]  
  3. //所有子視圖  
  4.  [self.view subviews]  
  5. //自身的window  
  6.  self.view.window  

循環(huán)一個(gè)視圖下面所有視圖的方法

 

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. }  

循環(huán)返回一個(gè)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. //加一個(gè)視圖到一個(gè)視圖里面  
  2. addSubview:  
  3. //將一個(gè)視圖移到前面  
  4. bringSubviewToFront:  
  5. //將一個(gè)視圖推送到背后  
  6. sendSubviewToBack:  
  7. //把視圖移除  
  8. removeFromSuperview  
  9. //插入視圖 并指定索引  
  10. insertSubview:atIndex:  
  11. //插入視圖在某個(gè)視圖之上  
  12. insertSubview:aboveSubview:  
  13. //插入視圖在某個(gè)視圖之下  
  14. insertSubview:belowSubview:  
  15. //交換兩個(gè)位置索引的視圖  
  16. exchangeSubviewAtIndex:withSubviewAtIndex:  

視圖回調(diào)

 

C代碼  收藏代碼
  1. //當(dāng)加入視圖完成后調(diào)用  
  2. (void)didAddSubview:(UIView *)subview  
  3. //當(dāng)視圖移動(dòng)完成后調(diào)用  
  4. (void)didMoveToSuperview  
  5. //當(dāng)視圖移動(dòng)到新的WINDOW后調(diào)用  
  6. (void)didMoveToWindow  
  7. //在刪除視圖之后調(diào)用  
  8. (void)willRemoveSubview:(UIView *)subview  
  9. //當(dāng)移動(dòng)視圖之前調(diào)用  
  10. (void)didMoveToSuperview:(UIView *)subview  
  11. //當(dāng)視圖移動(dòng)到WINDOW之前調(diào)用  
  12. (void)didMoveToWindow  

 給UIView設(shè)置標(biāo)記和檢索視圖

 

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. typedef struct CGPoint CGPoint;  
  7.   
  8. /* Sizes. */  
  9.   
  10. struct CGSize {  
  11.   CGFloat width;  
  12.   CGFloat height;  
  13. };  
  14. typedef struct CGSize CGSize;  
  15.   
  16. struct CGRect {  
  17.   CGPoint origin;  
  18.   CGSize size;  
  19. };  
  20. typedef struct CGRect CGRect;  
  21.   
  22.   
  23.   
  24. CGRect rect = CGRectMake(0,0,320,480);  
  25. UIView *view = [[UIView allow]initWithFrame:rect];  
  26.   
  27. //將String轉(zhuǎn)成CGPoint 如 @”{3.0,2.5}”    {x,y}  
  28. CGPoint CGPointFromString (  
  29.    NSString *string  
  30. );  
  31.   
  32. //將String轉(zhuǎn)成CGRect  @”{{3,2},{4,5}}”  {{x,y},{w, h}}  
  33. CGRect CGRectFromString (  
  34.    NSString *string  
  35. );  
  36.   
  37. //將String轉(zhuǎn)成CGSize @”{3.0,2.5}” {w, h}  
  38. CGSize CGSizeFromString (  
  39.    NSString *string  
  40. );  
  41.   
  42. //CGPoint轉(zhuǎn)成NSString  
  43. NSString * NSStringFromCGPoint (  
  44.    CGPoint point  
  45. );  
  46.   
  47. //CGRect轉(zhuǎn)成NSString  
  48. NSString * NSStringFromCGRect (  
  49.    CGRect rect  
  50. );  
  51.   
  52. //CGSize轉(zhuǎn)成NSString  
  53. NSString * NSStringFromCGSize (  
  54.    CGSize size  
  55. );  
  56.   
  57. //對(duì)一個(gè)CGRect進(jìn)行修改 以這個(gè)的中心來修改 正數(shù)表示更小(縮小) 負(fù)數(shù)表示更大(放大)  
  58. CGRect CGRectInset (  
  59.    CGRect rect,  
  60.    CGFloat dx,  
  61.    CGFloat dy  
  62. );  
  63.   
  64. //判斷兩個(gè)矩形是否相交  
  65. bool CGRectIntersectsRect (  
  66.    CGRect rect1,  
  67.    CGRect rect2  
  68. );  
  69.   
  70. //初始為0的  
  71. const CGPoint CGPointZero;  
  72. const CGRect CGRectZero;  
  73. const CGSize CGSizeZero;  
  74.   
  75. //創(chuàng)建CGPoint  
  76. CGPoint CGPointMake (  
  77.    CGFloat x,  
  78.    CGFloat y  
  79. );  
  80. //創(chuàng)建CGRect  
  81. CGRect CGRectMake (  
  82.    CGFloat x,  
  83.    CGFloat y,  
  84.    CGFloat width,  
  85.    CGFloat height  
  86. );  
  87. //創(chuàng)建CGSize  
  88. CGSize CGSizeMake (  
  89.    CGFloat width,  
  90.    CGFloat height  
  91. );  

仿射變換

 

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

如想復(fù)原

 

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

 直接設(shè)置視圖的中心

 

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

 中心

 

C代碼  收藏代碼
  1. CGRectGetMinX  
  2. CGRectGetMinY  
  3. //X的中間值  
  4. CGRectGetMidX  
  5. //Y的中間值  
  6. CGRectGetMidY  
  7. CGRectGetMaxX  
  8. CGRectGetMaxY  

  定時(shí)器

 

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

  定義視圖邊界

C代碼  收藏代碼
  1. typedef struct 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);  

仿射變換補(bǔ)充

//創(chuàng)建CGAffineTransform

C代碼  收藏代碼
  1. //angle 在0-2*PI之間比較好  旋轉(zhuǎn)  
  2. CGAffineTransform transform = CGAffineTransformMakeRotation(angle);  
  3. //縮放   
  4. CGAffineTransform transform = CGAffineTransformMakeScale(0.5f,0.5f);  
  5. //改變位置的  
  6. CGAffineTransform transform = CGAffineTransformMakeTranslation(50,60);  
  7.   
  8. //修改CGAffineTransform  
  9. //修改 縮放   
  10. CGAffineTransform scaled = CGAffineTransformScale(transform, degree, degree);  
  11. //修改 位置  
  12. CGAffineTransform transform = CGAffineTransformTranslate(  
  13.    CGAffineTransform t,  
  14.    CGFloat tx,  
  15.    CGFloat ty  
  16. );  
  17.   
  18. //修改角度   
  19. CGAffineTransform transform = CGAffineTransformRotate (  
  20.    CGAffineTransform t,  
  21.    CGFloat angle  
  22. );  
  23. //最后設(shè)置到VIEW  
  24.  [self.view setTransform:scaled];  
 

建立UIView動(dòng)畫塊

   //首先建立CGContextRef

C代碼  收藏代碼
  1. CGContextRef context = UIGraphicsGetCurrentContext();  
  2. //標(biāo)記動(dòng)畫開始  
  3. [UIView beginAnimations:nil context:context];  
  4. //定義動(dòng)畫加速或減速的方式  
  5. [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];  
  6. //定義動(dòng)畫的時(shí)長(zhǎng) 1秒  
  7. [UIView setAnimationDuration:1.0];  
  8. //中間處理 位置變化,,大小變化,,旋轉(zhuǎn),等等的  
  9. [[self.view viewWithTag:999] setAlpha:1.0f];  
  10. //標(biāo)志動(dòng)畫塊結(jié)束  
  11. [UIView commitAnimations];  
  12. //還可以設(shè)置回調(diào)  
  13. [UIView setAnimationDelegate:self];  
  14. //設(shè)置回調(diào)調(diào)用的方法  
  15. [UIView setAnimationDidStopSelector:@selector(animationFinished:)];  

  視圖翻轉(zhuǎn)

 

C代碼  收藏代碼
  1. UIView *whiteBackdrop = [self.view viewWithTag:100];  
  2. // Choose left or right flip 選擇左或右翻轉(zhuǎn)  
  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. //還有上翻和下翻兩種 如下  
  14. typedef enum {  
  15. //沒有任何效果  
  16.     UIViewAnimationTransitionNone,  
  17.     UIViewAnimationTransitionFlipFromLeft,  
  18.     UIViewAnimationTransitionFlipFromRight,  
  19.     UIViewAnimationTransitionCurlUp,  
  20.     UIViewAnimationTransitionCurlDown,  
  21. } UIViewAnimationTransition;  

  使用QuartzCore做動(dòng)畫

 

C代碼  收藏代碼
  1. //創(chuàng)建CATransition  
  2. CATransition *animation = [CATransition animation];  
  3. //設(shè)置代理  
  4. animation.delegate = self;  
  5. //設(shè)置動(dòng)畫過渡的時(shí)間  
  6. animation.duration = 4.0f;  
  7. //定義動(dòng)畫加速或減速的方式   
  8. animation.timingFunction = UIViewAnimationCurveEaseInOut;  
  9. //animation.type 表示設(shè)置過渡的種類 如 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. //設(shè)置漸變的方向,,上下左右  
  26.     if (isLeft)  
  27.         animation.subtype = kCATransitionFromRight;  
  28.     else  
  29.         animation.subtype = kCATransitionFromLeft;  
  30.   
  31. // Perform the animation  
  32.     UIView *whitebg = [self.view viewWithTag:10];  
  33.     NSInteger purple = [[whitebg subviews] indexOfObject:[whitebg viewWithTag:99]];  
  34.     NSInteger white = [[whitebg subviews] indexOfObject:[whitebg viewWithTag:100]];  
  35.     [whitebg exchangeSubviewAtIndex:purple withSubviewAtIndex:white];  
  36.     [[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.     }    

  上面這個(gè)是轉(zhuǎn)自這里的http://2015./blog/1122130

休眠一下

 

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

一個(gè)簡(jiǎn)單的通過圖片做的動(dòng)畫

 

C代碼  收藏代碼
  1. // Load butterfly images  
  2. NSMutableArray *bflies = [NSMutableArray array];  
  3. for (int i = 1; i <= 17; i++){  
  4.     [bflies addObject:[UIImage imageWithContentsOfFile:[[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.        //設(shè)置動(dòng)畫的圖片  
  9. butterflyView.animationImages = bflies;  
  10.        //設(shè)置時(shí)間  
  11. butterflyView.animationDuration = 0.75f;  
  12. [self.view addSubview:butterflyView];  
  13.        //開始動(dòng)畫  
  14. [butterflyView startAnimating];  
  15. [butterflyView release];  
 

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn),。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式,、誘導(dǎo)購(gòu)買等信息,,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,,請(qǐng)點(diǎn)擊一鍵舉報(bào),。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多