Ben var UITableViewiOS 8 altında çalışan ve film şeridindeki sınırlamalardan otomatik hücre yükseklikleri kullanıyorum.
Hücrelerimden biri tek bir tane içeriyor UITextViewve kullanıcı girişine göre daralması ve genişletmesi gerekiyor - metni küçültmek / genişletmek için dokunun.
Metin görünümüne bir çalışma zamanı kısıtlaması ekleyerek ve kullanıcı olaylarına yanıt olarak kısıtlama sabitini değiştirerek bunu yapıyorum:
-(void)collapse:(BOOL)collapse; {
_collapsed = collapse;
if(collapse)
[_collapsedtextHeightConstraint setConstant: kCollapsedHeight]; // 70.0
else
[_collapsedtextHeightConstraint setConstant: [self idealCellHeightToShowFullText]];
[self setNeedsUpdateConstraints];
}
Ne zaman bunu yaparsam, ben tableViewgüncellemeler sarın ve arayın [tableView setNeedsUpdateConstraints]:
[tableView beginUpdates];
[_briefCell collapse:!_showFullBriefText];
[tableView setNeedsUpdateConstraints];
// I have also tried
// [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop];
// with exactly the same results.
[tableView endUpdates];
Bunu yaptığımda, hücrem genişliyor (ve bunu yaparken canlandırıyor) ancak bir kısıtlama uyarısı alıyorum:
2014-07-31 13:29:51.792 OneFlatEarth[5505:730175] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x7f94dced2b60 V:[UITextView:0x7f94d9b2b200'Brief text: Lorem Ipsum i...'(388)]>",
"<NSLayoutConstraint:0x7f94dced2260 V:[UITextView:0x7f94d9b2b200'Brief text: Lorem Ipsum i...']-(15)-| (Names: '|':UITableViewCellContentView:0x7f94de5773a0 )>",
"<NSLayoutConstraint:0x7f94dced2350 V:|-(6)-[UITextView:0x7f94d9b2b200'Brief text: Lorem Ipsum i...'] (Names: '|':UITableViewCellContentView:0x7f94de5773a0 )>",
"<NSLayoutConstraint:0x7f94dced6480 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7f94de5773a0(91)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7f94dced2b60 V:[UITextView:0x7f94d9b2b200'Brief text: Lorem Ipsum i...'(388)]>
388 benim hesaplanan yüksekliğim, UITextViewXcode / IB'deki diğer kısıtlamalar benimdir.
Sonuncusu beni rahatsız ediyor - UIView-Encapsulated-Layout-Heightilk oluşturulduğunda hücrenin hesaplanan yüksekliği olduğunu tahmin ediyorum - ( UITextViewboyumu> = 70.0 olarak ayarladım ) ancak bu türden bir kısıtlamanın daha sonra bir geçersiz kıldığı doğru görünmüyor güncellenmiş kullanıcı cnstraint.
Daha da kötüsü, düzen kodu yükseklik kısıtlamamı kırmaya çalıştığını söylese de, hücre yüksekliğini yeniden hesaplamaya devam ediyor ve her şey istediğim gibi çiziyor.
Öyleyse, nedir NSLayoutConstraint UIView-Encapsulated-Layout-Height(tahmin ediyorum ki otomatik hücre boyutlandırması için hesaplanan yükseklik) ve bunu temiz bir şekilde yeniden hesaplamaya zorlamaya nasıl devam etmeliyim?
self.contentView.autoresizingMask = UIViewAutoresizingFlexibleHeight;. Otomatik boyutlandırma maskesinin başlangıçta ayarlanmasının son kısıtlamanın eklenmesini durdurduğunu düşünüyorum. Bu çözümü burada buldum: github.com/wordpress-mobile/WordPress-iOS/commit/…
<rect key="frame" x="0.0" y="0.0" width="600" height="110"/>tanımındaki satırı eksik olması ve bunun bir IB hatası olduğuna inanmamı sağlamasıydı . En azından benimki zaten.