VFL +AutoLayout

 

橫豎屏事件響應(viewWillLayoutSubviews和通知)兩種方式

 

 http://blog.csdn.net/nogodoss/article/details/17246489app

一,NSLayoutConstraint APIide

1,constraintsWithVisualFormat:ui

+ (NSArray *)constraintsWithVisualFormat:(NSString *)format options:(NSLayoutFormatOptions)opts metrics:(NSDictionary *)metrics views:(NSDictionary *)views;

參數介紹:編碼

format:此參數爲你的vfl語句,好比:@"H:|-[button]-|"  spa

    水平方向          H:        垂直方向          V:  .net

    Views         [view]    SuperView      |    code

    關係         >=,==,<=orm

    空間,間隙       -blog

    優先級        @value事件

opts:枚舉參數,默認寫0,具體跟據你所實現的需求去選擇你想要的枚舉

metrics:這裏是一個字典,當在format中使用了動態數據好比上現這句:@"H:|-[button(==width)]-|",表示這個button的寬度爲width,那麼這個參數去哪裏找呢?就是在這個字典裏面找到key對就的值,若是沒有找到這個值,app就會crash.

views:顧名思義,這是傳全部你在vfl中使用到的view,那在上面這句例子中的應該怎麼傳呢?結果是這樣的:NSDictionaryOfVariableBindings(button).若是你使用到了多個view,就能夠這樣NSDictionaryOfVariableBindings(button,button1,button3...),這個名字也要跟參數format中的一一對應,缺一不可.

2, addConstraint:

- (void)addConstraint:(NSLayoutConstraint *)constraint NS_AVAILABLE_IOS(6_0); // This method will be deprecated in a future release and should be avoided.  Instead, set NSLayoutConstraint's active property to YES.
- (void)addConstraints:(NSArray *)constraints NS_AVAILABLE_IOS(6_0); // This method will be deprecated in a future release and should be avoided.  Instead use +[NSLayoutConstraint activateConstraints:].
- (void)removeConstraint:(NSLayoutConstraint *)constraint NS_AVAILABLE_IOS(6_0); // This method will be deprecated in a future release and should be avoided.  Instead set NSLayoutConstraint's active property to NO.
- (void)removeConstraints:(NSArray *)constraints NS_AVAILABLE_IOS(6_0); // This method will be deprecated in a future release and should be avoided.  Instead use +[NSLayoutConstraint deactivateConstraints:].

 

eg:

 

 

 

 

二,
編碼模式中,
1.addConstraint(s)前,view應該去部被addSubView上去了。
2.沒必要給views寫frame
3.給必要的view關掉AutoresizeingMask。[_aView setTranslatesAutoresizingMaskIntoConstraints:NO];
4.UILabel換行要寫linebreakMode,要寫numberOfLines(iOS7.0默認好像是1,坑爹了)
5.UILabel要想換行,必定要添加preferredMaxLayoutWidth。不然無法初始化寬度。

 

 

3, 

動態計算UITableViewCell高度詳解

http://www.ifun.cc/blog/2014/02/21/dong-tai-ji-suan-uitableviewcellgao-du-xiang-jie/#md-5 

相關文章
相關標籤/搜索