-(IBAction)nextButtonTapped:(id)sender {
if (moreItemsgridView.contentOffset.x<=moreItemsgridView.contentSize.width) {
CGRect frame;
frame.origin.x = moreItemsgridView.contentOffset.x + moreItemsgridView.frame.size.width;
frame.origin.y = 0;
frame.size = moreItemsgridView.frame.size;
[moreItemsgridView scrollRectToVisible:frame animated:YES];
//[moreItemsgridView setContentOffset:CGPointMake(moreItemsgridView.contentOffset.x + moreItemsgridView.contentSize.width, 0) animated:NO];
}
}
-(IBAction)previousButtonTapped:(id)sender {
if (moreItemsgridView.contentOffset.x>=moreItemsgridView.frame.size.width) {
CGRect frame;
frame.origin.x = moreItemsgridView.contentOffset.x - moreItemsgridView.frame.size.width;
frame.origin.y = 0;
frame.size = moreItemsgridView.frame.size;
[moreItemsgridView scrollRectToVisible:frame animated:YES];
}
}
当我点击“下一步”按钮时,我的图像可以正确滚动,但是当我单击“上一步”按钮时,它可以正确滚动,但最后只显示一半的视图...我在做什么错...请对此进行帮助。 ..
答案 0 :(得分:-1)
更新框架后,呼叫[self.view layoutIfNeeded];
。
-(IBAction)nextButtonTapped:(id)sender {
if (moreItemsgridView.contentOffset.x<=moreItemsgridView.contentSize.width) {
CGRect frame;
frame.origin.x = moreItemsgridView.contentOffset.x + moreItemsgridView.frame.size.width;
frame.origin.y = 0;
frame.size = moreItemsgridView.frame.size;
[moreItemsgridView scrollRectToVisible:frame animated:YES];
//[moreItemsgridView setContentOffset:CGPointMake(moreItemsgridView.contentOffset.x + moreItemsgridView.contentSize.width, 0) animated:NO];
[self.view layoutIfNeeded]
}
}
-(IBAction)previousButtonTapped:(id)sender {
if (moreItemsgridView.contentOffset.x>=moreItemsgridView.frame.size.width) {
CGRect frame;
frame.origin.x = moreItemsgridView.contentOffset.x - moreItemsgridView.frame.size.width;
frame.origin.y = 0;
frame.size = moreItemsgridView.frame.size;
[moreItemsgridView scrollRectToVisible:frame animated:YES];
[self.view layoutIfNeeded]
}
}