作者:只属于我一个人的秘密 | 来源:互联网 | 2023-09-10 12:09
helpmePLEASE,todetectwhichImageisonscrollviewwhenIscrollit.请帮我,滚动时检测哪个图像在滚动视图上。-(vo
help me PLEASE, to detect which Image is on scrollview when I scroll it.
请帮我,滚动时检测哪个图像在滚动视图上。
- (void)viewDidLoad
{
[super viewDidLoad];
NSArray *colors = [[NSArray alloc] initWithObjects:@"ip1.jpg", @"ip2.jpg", @"ip3.jpg", @"ip4.jpg", @"ip5.jpg", @"ip6.jpg", @"ip7.jpg", @"ip8.jpg", @"ip9.jpg", @"ip10.jpg",@"ip11.jpg",@"ip12.jpg",@"ip13.jpg",@"ip14.jpg",@"ip15.jpg",@"ip16.jpg",@"ip17.jpg",@"ip18.jpg",@"ip19.jpg",@"ip20.jpg",@"ip21.jpg", nil];
NSMutableArray *imgArray = [[NSMutableArray alloc] init];
UIImageView *tempImageView;
for(NSString *name in colors) {
tempImageView = [[UIImageView alloc] init];
tempImageView.cOntentMode= UIViewContentModeScaleAspectFill;
tempImageView.image = [UIImage imageNamed:name];
[imgArray addObject:tempImageView];
}
CGSize pageSize = scrollView.frame.size; // scrollView is an IBOutlet for our UIScrollView
NSUInteger page = 0;
for(prevView in imgArray) {
[scrollView addSubview:prevView];
// This is the important line
prevView.frame = CGRectMake(pageSize.width * page++ + 30, 0, pageSize.width - 60, pageSize.height);
}
scrollView.cOntentSize= CGSizeMake(pageSize.width * [imgArray count], pageSize.height);
}
- (void)scrollViewDidScroll:(UIScrollView *)sender {
if (!pageControlBeingUsed) {
// Switch the indicator when more than 50% of the previous/next page is visible
CGFloat pageWidth = self.scrollView.frame.size.width;
int page = floor((self.scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
self.pageControl.currentPage = page;
}
}
Help me please. If i use slog to show CurrentPage, it shows me like "117892", I just Need a NSLog that will show me current image from my "colors" NSArray. Thanks a lot
请帮帮我。如果我使用slog来显示CurrentPage,它会显示我像“117892”,我只需要一个NSLog,它将显示我的“颜色”NSArray的当前图像。非常感谢
1 个解决方案