gpt4 book ai didi

iphone - 检测哪个图像在 ScrollView 上

转载 作者:行者123 更新时间:2023-11-29 13:23:30 25 4
gpt4 key购买 nike

请帮助我,在我滚动时检测哪个图像在 ScrollView 上。

- (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;



}
}

请帮帮我。如果我使用 slog 来显示 CurrentPage,它会向我显示“117892”,我只需要一个 NSLog 来显示我的“颜色”NSArray 中的当前图像。非常感谢

最佳答案

试试这个,您可以将“page”变量声明为全局变量,然后按代码所示传递

NSLog(@"%@",[colors objectAtIndex:page]);

关于iphone - 检测哪个图像在 ScrollView 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13776026/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com