पर काम नहीं कर रहा है मेरे पास एक सरल UICollectionView है जिसमें एक एकल UITextView है। UITextView सेल के किनारों पर बाध्य है, इसलिए उन्हें सेल आकार के समान आकार में रहना चाहिए।UICollectionViewCell में ऑटो लेआउट
मेरी समस्या यह है कि किसी कारण से ये बाधाएं काम नहीं कर रही हैं जब मैं संग्रह के माध्यम से सेल आकार निर्दिष्ट करता हूं: लेआउट: sizeForItemAtIndexPath:।
मेरे पास स्टोरीबोर्ड में सेल आकार 320x50 पर सेट है। यदि मैं आकार आकार के साथ सेल आकार की 2 गुना ऊंचाई के साथ एक आकार वापस करता हूं, तो IITextView सेट की गई बाधाओं के बावजूद एक ही ऊंचाई पर रहता है। मैं एक्सकोड 6 जीएम का उपयोग कर रहा हूँ।
मेरा विचार नियंत्रक कोड है:
@implementation TestViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
UICollectionViewCell *c = [self.collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]];
NSLog(@"%f", c.frame.size.height);
UITextView *tv = (UITextView *)[c viewWithTag:9];
NSLog(@"%f", tv.frame.size.height);
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return 1;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewFlowLayout *flowLayout = (UICollectionViewFlowLayout *)collectionView.collectionViewLayout;
CGSize size = flowLayout.itemSize;
size.height = size.height * 2;
return size;
}
@end
viewDidAppear उन लॉग: मुझे का उत्पादन दे:
100,00000
50,00000
आप देख सकते हैं, UITextView ऊंचाई नहीं है सेल ऊंचाई के साथ बदलें।
यहाँ स्टोरीबोर्ड मैं एक UITextView UICollectionViewCell में विवश के साथ स्थापित की एक स्क्रीनशॉट:
मैं ऑटो लेआउट की कमी का उपयोग कर पता UITableViewCells और गतिशील आकार बदलने के साथ ठीक काम करता है। मुझे नहीं पता कि यह इस मामले में क्यों काम नहीं कर रहा है। क्या किसी के पास कोई विचार है?
बढ़िया! तुम मेरा दिन बचाओ! आईओएस 8 एक्सकोड 6 आदि स्थापित करने के बाद यह समाधान मेरे लिए काम कर रहा है। मेरे सभी टेबलव्यू ने यूकोलेक्लेव्यूव्यू सेल आकार को अनुकूलित नहीं किया है। धन्यवाद :) – Fjohn
यदि यह आपके लिए काम नहीं करता है तो कोशिश करें: awakerFromNib() {contentView.autoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight} –
आईओएस 8 के साथ आईपैड पर मेरा एक ही मुद्दा था, और इस समाधान ने समस्या को भी ठीक किया। धन्यवाद! – almas