2013-09-24 25 views
9

Trước đây trong iOS6, bộ điều khiển xem tin nhắn trò chuyện của tôi được hiển thị và hoạt ảnh chính xác với các hạn chế tự động xây dựng cẩn thận trong IB. Dưới đây là quan điểm hệ thống phân cấp hiện tại với những hạn chế loại bỏ trong Xcode 5:Vấn đề iOS7 với NSIBPrototypingLayoutConstraint autolayout ràng buộc được tạo ra bởi Interface Builder

IB layout

Sau khi nâng cấp lên XCode 5 và iOS7, tôi thấy tôi cần thiết để xóa tất cả các hạn chế cũ để chiếm trên thanh trạng thái mờ mặc định , nếu không thanh công cụ của tôi sẽ nằm trong thanh trạng thái. Điều này xảy ra mặc dù gọi setEdgesForExtendedLayout: với UIRectEdgeNone.

bây giờ tôi đang cố gắng để tạo ra tất cả những ràng buộc theo chương trình trong viewDidLoad:

// self.view.translatesAutoresizingMaskIntoConstraints = NO; // errors either way 
NSArray *viewHorizConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_toolbar]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_toolbar)]; 
[self.view addConstraints:viewHorizConstraints]; 
viewHorizConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_viewContainer]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_viewContainer)]; 
[self.view addConstraints:viewHorizConstraints]; 

NSArray *viewVertConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-(20)-[_toolbar(44)]-[_viewContainer]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_toolbar, _viewContainer)]; 
[self.view addConstraints:viewVertConstraints]; 

NSArray *tableContainerVertConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_tableView(<[email protected])][_viewInputContainer(44)]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_tableView, _viewInputContainer)]; 
[_viewTableContainer addConstraints:tableContainerVertConstraints]; 


NSArray *containerVertConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_viewTableContainer][_viewOptions]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_viewTableContainer, _viewOptions)]; 
[_viewContainer addConstraints:containerVertConstraints]; 

// _constraintContainerVertSpace = [NSLayoutConstraint constraintWithItem:_viewTableContainer attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:_viewContainer attribute:NSLayoutAttributeTrailing multiplier:1 constant:0]; // same as below 

containerVertConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[_viewTableContainer]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_viewTableContainer)]; 
_constraintContainerVertSpace = [containerVertConstraints lastObject]; 
[_viewContainer addConstraint:_constraintContainerVertSpace]; 

containerVertConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-(>=0)-[_viewOptions]-(>[email protected])-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_viewOptions)]; 
[_viewContainer addConstraints:containerVertConstraints]; 

Tuy nhiên, nếu tôi cố gắng để thay đổi các hạn chế không gian theo chiều dọc giữa containerView và tableContainerView của tôi, tôi nhận lỗi. (. Tôi đang cố gắng để thay đổi kích thước tableContainerView co lại với sự xuất hiện của bàn phím)

[UIView animateWithDuration:0.25f 
         delay:0 
        options:UIViewAnimationOptionCurveEaseInOut 
       animations:^{ 
        _constraintContainerVertSpace.constant = -keyboardHeight; 
       } completion:nil]; 

Đây là những khó khăn mà không đáp ứng cùng một lúc:

(
"<NSIBPrototypingLayoutConstraint:0x140d7bb0 'IB auto generated at build time for view with fixed frame' V:|-(460)-[UIView:0x140ddef0] (Names: '|':UIView:0x140dde60)>", 
"<NSIBPrototypingLayoutConstraint:0x140d7c10 'IB auto generated at build time for view with fixed frame' V:[UIView:0x140ddef0(44)]>", 
"<NSLayoutConstraint:0x14d9db30 V:[UIView:0x140ddef0]-(0)-| (Names: '|':UIView:0x140dde60)>", 
"<NSIBPrototypingLayoutConstraint:0x140e0290 'IB auto generated at build time for view with fixed frame' V:|-(0)-[UIView:0x140dde60] (Names: '|':UIView:0x140dddd0)>", 
"<NSLayoutConstraint:0x14d9df60 V:[UIView:0x140dde60]-(-216)-| (Names: '|':UIView:0x140dddd0)>", 
"<NSIBPrototypingLayoutConstraint:0x140e0830 'IB auto generated at build time for view with fixed frame' V:|-(64)-[UIView:0x140dddd0] (Names: '|':UIView:0x140e0470)>", 
"<NSLayoutConstraint:0x14d9d820 V:[UIView:0x140dddd0]-(0)-| (Names: '|':UIView:0x140e0470)>", 
"<NSAutoresizingMaskLayoutConstraint:0x1403a0b0 h=--& v=--& V:[UIView:0x140e0470(568)]>" 
) 

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x14d9db30 V:[UIView:0x140ddef0]-(0)-| (Names: '|':UIView:0x140dde60)> 

UIView: 0x140dde60 trong trường hợp này là _viewTableContainer. 0x140ddef0 = _viewInputContainer. 0x140dddd0 = _viewContainer.

Tại sao điều này NSIBPrototypingLayoutConstraint V: | - (460) - [UIView: 0x140ddef0 (_viewInputContainer)] được tạo ra bởi IB khi tôi đã thiết translatesAutoresizingMaskIntoConstraints để NO, và khi tôi đã định nghĩa các ràng buộc dọc rõ ràng giữa _viewInputContainer và _tableView phía trên nó?

Tôi đã thử sử dụng Bố cục Cocoa trong Công cụ nhưng có quá nhiều tiếng ồn để tạo bất kỳ ý nghĩa nào về nó.

+0

Kiểm tra câu hỏi rất giống ở đây: http: // stackoverflow.com/questions/19015215/trouble-with-autolayout-on-uitableviewcell/19020006 # 19020006 – smileyborg

Trả lời

18

Tôi đã phải xóa thủ công các ràng buộc trên các chế độ xem ngoài việc sử dụng translatesAutoresizingMaskIntoConstraints.

[_viewContainer removeConstraints:_viewContainer.constraints]; 
[self.view removeConstraints:self.view.constraints]; 

Sau khi thêm những thay đổi này, không còn lỗi nào với hoạt ảnh.

10

Để xóa NSIBPrototypingLayoutConstraint được tạo bởi IB, nó có thể được giải quyết bằng cách thêm một số ràng buộc giả trên IB và đặt chúng remove at build time. Sau đó, IB sẽ không tạo ra NSIBPrototypingLayoutConstraint cho bạn.

+2

@smileyborg đưa ra [liên kết tốt] (http://stackoverflow.com/a/19020006/419348). Nó rõ ràng hơn về câu hỏi này. – AechoLiu

3

buộc Swift:

view.removeConstraints(view.constraints) 

Ngoài ra, nếu bạn muốn loại bỏ những hạn chế đối với một mục giao diện cụ thể trong mã, bạn có thể loại bỏ chúng cho chỉ là một đối tượng. Dưới đây là một vài ví dụ:

myTableView.removeConstraints(myTableView.constraints) 
myButton.removeConstraints(myButton.constraints) 
myImageView.removeConstraints(myImageView.constraints) 

Điều này đặc biệt hữu ích nếu bạn đang tạo một phiên bản ứng dụng trả phí hoặc miễn phí. Bạn có thể thực hiện hầu hết bố cục giao diện trong trình tạo giao diện và sau đó thực hiện các chỉnh sửa cho bố cục trong mã bằng Ngôn ngữ định dạng hình ảnh.

+0

Nó hoạt động cho tôi. Cảm ơn! –

Các vấn đề liên quan