我有一个包含4个图像的视图控制器,我实现了这些图像的分页这是我的代码
- (void)viewDidLoad {
[super viewDidLoad];
[imageViewObj setImage:[UIImage imageNamed:@"hand1@2x"]];
NSTimer *ImgChangeTimer = [NSTimer scheduledTimerWithTimeInterval:2.0
target:self
selector:@selector(changeImage)
userInfo:nil
repeats:YES];
pageControlBeingUsed = NO;
NSArray *colors = [NSArray arrayWithObjects:[UIImage imageNamed:@"help3@2x"], [UIImage imageNamed:@"help4@2x"], [UIImage imageNamed:@"help2@2x"],[UIImage imageNamed:@"help1@2x"] ,nil];
for (int i = 0; i < colors.count; i++) {
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width *i;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
UIImageView*subview = [[UIView alloc] initWithFrame:frame];
UIImage *imggg = [colors objectAtIndex:i];
[subview setBackgroundColor:[UIColor colorWithPatternImage:imggg]];
[self.scrollView addSubview:subview];
[self.scrollView addSubview:imageViewObj];
[subview release];
}
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * colors.count, self.scrollView.frame.size.height);
self.pageControl.currentPage = 0;
self.pageControl.numberOfPages = colors.count;
我需要的是我想在最后一张图片中放置一个关闭按钮,或者关闭按钮被隐藏为前三张图像,并且当用户分页最后一张图片时将取消隐藏。是否有任何方法可以执行此操作? 提前致谢。 修改
if (self.pageControl.currentPage == 0) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"df" message:@"okkkk" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}
我把它放在viewdidlod中,我得到了alertview
但是当我把“4”而不是“0”时,我没有得到警报视图
答案 0 :(得分:0)
尝试使用以下代码,代码段:
NSInteger page;
page = (scrollView.contentOffset.x/scrollView.frame.size.width);
if (page == 3) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"df" message:@"okkkk" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}