我的iOS应用中有UIScrollView
。在UIScrollView
我有一个UITextView
和一个UIImageView
。我需要的是UIImageView
滚动,直到它的底部大约33%从屏幕顶部移除然后粘住。
这是我的viewDidLoad
:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
CGRect fullScreenRect=[[UIScreen mainScreen] applicationFrame];
UIScrollView *scrollView =[[UIScrollView alloc] initWithFrame:fullScreenRect];
scrollView.contentSize = CGSizeMake(self.view.bounds.size.width, 758);
self.view = scrollView;
self.automaticallyAdjustsScrollViewInsets = NO;
self.view.backgroundColor = [UIColor whiteColor];
NSString *imageUrl = [NSString stringWithFormat: @"%@", [self.stream plaatje]];
self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 64, self.view.bounds.size.width, self.view.frame.size.height-164)];
[self.imageView sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:[UIImage imageNamed:@"tile-blue.png"]];
[self.view addSubview:self.imageView];
UITextView *content = [[UITextView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height-100, self.view.bounds.size.width, self.view.bounds.size.height)];
content.text = textString;
content.textColor = [UIColor blackColor];
content.backgroundColor = [UIColor whiteColor];
content.font = [UIFont fontWithName:@"SourceSansPro-Regular" size:18];
content.textAlignment = NSTextAlignmentLeft;
[content sizeToFit];
[content layoutIfNeeded];
[self.view addSubview:content];
CGFloat width = self.view.bounds.size.width;
CGFloat imageHeight = CGRectGetMaxY(self.imageView.frame);
CGFloat contentHeight = CGRectGetMaxY(content.frame);
[scrollView setContentSize:(CGSizeMake(width, contentHeight))];
}
现在,我对此做了一些研究,我95%确定我需要这样做:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGRect headerFrame = self.imageView.frame;
headerFrame.origin.y = MAX(self.imageView.frame.origin.y, scrollView.contentOffset.y);
self.imageView.frame = headerFrame;
}
虽然目前的实施没有做任何事情。我该如何解决这个问题?