UIView 用法展示 CGAffineTransformIdentity CGAffineTransformMakeTranslation CGAffineTransformMakeScale

 UIView : UIResponder
/**
 *  通過一個frame來初始化一個UI控件
 */
- (id)initWithFrame:(CGRect)frame;

// YES:能夠跟用戶進行交互
@property(nonatomic,getter=isUserInteractionEnabled) BOOL userInteractionEnabled;  // default is YES

// 控件的一個標記(父控件可以通過tag找到對應的子控件)
@property(nonatomic)                                 NSInteger tag;                // default is 0

// 圖層(可以用來設置圓角效果\陰影效果)
@property(nonatomic,readonly,retain)                 CALayer  *layer;

@interface UIView(UIViewGeometry)
// 位置和尺寸(以父控件的左上角爲座標原點(0, 0))
@property(nonatomic) CGRect            frame;

// 位置和尺寸(以自己的左上角爲座標原點(0, 0))
@property(nonatomic) CGRect            bounds;

// 中點(以父控件的左上角爲座標原點(0, 0))
@property(nonatomic) CGPoint           center;      

// 形變屬性(平移\縮放\旋轉)
@property(nonatomic) CGAffineTransform transform;   // default is CGAffineTransformIdentity

// YES:支持多點觸摸
@property(nonatomic,getter=isMultipleTouchEnabled) BOOL multipleTouchEnabled;   // default is NO
@end

@interface UIView(UIViewHierarchy)
// 父控件
@property(nonatomic,readonly) UIView       *superview;

// 子控件(新添加的控件默認都在subviews數組的後面, 新添加的控件默認都顯示在最上面\最頂部)
@property(nonatomic,readonly,copy) NSArray *subviews;

// 獲得當前控件所在的window
@property(nonatomic,readonly) UIWindow     *window;

// 從父控件中移除一個控件
- (void)removeFromSuperview;

// 添加一個子控件(可以將子控件插入到subviews數組中index這個位置)
- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index;

// 交換subviews數組中所存放子控件的位置
- (void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2;

// 添加一個子控件(新添加的控件默認都在subviews數組的後面, 新添加的控件默認都顯示在最上面\最頂部)
- (void)addSubview:(UIView *)view;

// 添加一個子控件view(被擋在siblingSubview的下面)
- (void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview;

// 添加一個子控件view(蓋在siblingSubview的上面)
- (void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview;

// 將某個子控件拉到最上面(最頂部)來顯示
- (void)bringSubviewToFront:(UIView *)view;

// 將某個子控件拉到最下面(最底部)來顯示
- (void)sendSubviewToBack:(UIView *)view;

/**系統自動調用(留給子類去實現)**/
- (void)didAddSubview:(UIView *)subview;
- (void)willRemoveSubview:(UIView *)subview;

- (void)willMoveToSuperview:(UIView *)newSuperview;
- (void)didMoveToSuperview;
- (void)willMoveToWindow:(UIWindow *)newWindow;
- (void)didMoveToWindow;
/**系統自動調用**/

// 是不是view的子控件或者子控件的子控件(是否爲view的後代)
- (BOOL)isDescendantOfView:(UIView *)view;  // returns YES for self.

// 通過tag獲得對應的子控件(也可以或者子控件的子控件)
- (UIView *)viewWithTag:(NSInteger)tag;     // recursive search. includes self

/**系統自動調用(留給子類去實現)**/
// 控件的frame發生改變的時候就會調用,一般在這裏重寫佈局子控件的位置和尺寸
// 重寫了這個寫方法後,一定調用[super layoutSubviews];
- (void)layoutSubviews;

@end

@interface UIView(UIViewRendering)
// YES : 超出控件邊框範圍的內容都剪掉
@property(nonatomic)                 BOOL              clipsToBounds;

// 背景色
@property(nonatomic,copy)            UIColor          *backgroundColor; // default is nil

// 透明度(0.0~1.0)
@property(nonatomic)                 CGFloat           alpha;                      // default is 1.0

// YES:不透明  NO:透明
@property(nonatomic,getter=isOpaque) BOOL              opaque;                     // default is YES

// YES : 隱藏  NO : 顯示
@property(nonatomic,getter=isHidden) BOOL              hidden;

// 內容模式
@property(nonatomic)                 UIViewContentMode contentMode;                // default is UIViewContentModeScaleToFill
@end
//動畫
@interface UIView(UIViewAnimationWithBlocks)
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion;
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion;

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations;
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay usingSpringWithDamping:(CGFloat)dampingRatio initialSpringVelocity:(CGFloat)velocity options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion;

view還有以下用法。用來實現一些動態庫擴展,展示撲面而來的視覺效果

CoreGraphics框架中的CGAffineTransform類可用於設定UIView的transform屬性,控制視圖的縮放、旋轉和平移操作:

另稱放射變換矩陣,可參照線性代數的矩陣實現方式0.0

這裏附上的CGAffineTransform官方文檔:

https://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CGAffineTransform/index.html

 

總得來說,這個類中包含3張不同類型,分別使用如下3個方法創建數值;

1.CGAffineTransformMakeTranslation(CGFloat tx, CGFloat ty)(平移:設置平移量)

2.CGAffineTransformMakeScale(CGFloat sx, CGFloat sy)(縮放:設置縮放比例)僅通過設置縮放比例就可實現視圖撲面而來和縮進頻幕的效果。

3. (CGFloat angle)(旋轉:設置旋轉角度)

以上3個都是針對視圖的原定最初位置的中心點爲起始參照進行相應操作的,在操作結束之後可對設置量進行還原:

view.transform=CGAffineTransformIdentity;

 

另外還可以通過CGAffineTransformTranslate等方法對現有的transform進行進一步處理;


發佈了72 篇原創文章 · 獲贊 10 · 訪問量 10萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章