我有一些问题。我想在scrollview中显示静态和动态对象。我有IBOutlets,他们是连接的。我想更改消息和标题,它们是在代码中手动创建的。所有其他对象都是静态的。我的代码在这里:
.h文件:
@interface MessageContentViewController (){
IBOutlet UIImageView *avatarImageView;
IBOutlet UIScrollView *scrollView;
IBOutlet UIImageView *msgBoardImg;
IBOutlet UIImageView *topBarImg;
IBOutlet UIButton *backBtn;
NSMutableArray *allMessages;
}
@property int indexOfMsg;
@end
.m文件:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"background.jpg"]]];
[self.navigationController setNavigationBarHidden:YES animated:YES];
[scrollView setContentSize:CGSizeMake(scrollView.frame.size.width * allMessages.count, 0)];
[scrollView setPagingEnabled:YES];
[scrollView scrollRectToVisible:CGRectMake(scrollView.frame.size.width * indexOfMsg, scrollView.frame.origin.y, scrollView.frame.size.width, scrollView.frame.size.height) animated:NO];
for (int i = 0; i < allMessages.count; i++) {
UIView *tempSubView = [[UIView alloc] initWithFrame:CGRectMake(self.view.frame.size.width * i, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height)];
[tempSubView addSubview:topBarImg];
[tempSubView addSubview:backBtn];
[tempSubView addSubview:msgBoardImg];
[tempSubView addSubview:avatarImageView];
[scrollView addSubview:tempSubView];
}
[scrollView setContentOffset: CGPointMake(scrollView.frame.size.width * indexOfMsg, 0)];
CGRect currentViewFrame = CGRectMake(scrollView.frame.size.width * indexOfMsg, scrollView.frame.origin.y, scrollView.frame.size.width, scrollView.frame.size.height);
[scrollView scrollRectToVisible:currentViewFrame animated:NO];
}
.xib文件:
请帮帮我。提前谢谢。
答案 0 :(得分:0)
您应该实现scrollview的委托方法scrollViewDidEndDecelerating:
,您可以在其中检测滚动距离,然后为不同的滚动视图设置不同的标题和消息。