我很难搞清楚如何在DetailView故事板中动态定位对象。动态定位故事板中的iOS对象
对于初学者来说,该应用遵循传统博客格式,其中,所述马西德威是一个UITableView(或UICollectionView)具有多个桩。
当用户点击其中的一个,一个SEGUE导致的DetailView。
一切正确加载,除了在的DetailView的元件的定位。
这是它的外观:
顶部UIImageView
有固定的高度,因此不会与Post Text Label
重叠。
然而,Post Text Label
具有可变的高度,一些后文本是比别人更长的时间。这由我正在使用的类别来动态调整大小(resizeToFit
)。这一切都很好。
现在的问题是,当Post Text Label
垂直增长时,我需要View - Byline
(绿色矩形)根据Post Text Label
的垂直尺寸向下移动。我不能让它向下移动。
您可以看到我将所有View - Byline
对象放在视图中,因此它们通过仅将View - Byline
以编程方式更改位置而一起移动。
你知道我可以用它来做到这一点的任何方法吗?任何指针,教程或智慧非常感谢。
DetailViewController.h
#import <UIKit/UIKit.h>
@interface DetailViewController : UIViewController {
IBOutlet UIImageView *postThumbView;
IBOutlet UILabel *postTextLabel;
IBOutlet UIImageView *postAuthorPictureView;
IBOutlet UILabel *postAuthorNameLabel;
IBOutlet UILabel *postTimestampLabel;
IBOutlet UIScrollView *scroller;
IBOutlet UIView *postBylineView;
}
@property (strong, nonatomic) id detailItem;
@end
DetailViewController.m
...
[postThumbView setImageWithURL:[NSURL URLWithString:postThumbUrl] placeholderImage:[UIImage imageNamed:@"default"]];
[postAuthorPictureView setImageWithURL:[NSURL URLWithString:authorPicture] placeholderImage:[UIImage imageNamed:@"default"]];
postTextLabel.text = postText;
postTextLabel.frame = CGRectMake(postTextLabel.frame.origin.x,
postThumbView.frame.origin.y + postThumbView.frame.size.height,
postTextLabel.frame.size.width,
postTextLabel.frame.size.height);
[postTextLabel resizeToFit];
postAuthorNameLabel.text = postAuthorName;
postTimestampLabel.text = postTimestamp;
您是否正在使用具有AutoResizing Masks的AutoLayout或iOS 4.3+的iOS 6+?我问,因为具有AutoLayout的iOS 6+将会非常轻松地满足您的要求。 –
@RoboticCat我正在使用ios6 - 我一直在保持“使用autolayout”框中选中,但没有注意到它在我的问题上有所作为 - 我该如何处理这个问题? – pepe