热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

检测哪个图像在滚动视图上-detectwhichimageisonscrollview

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 个解决方案

#1


1  

Try this,you can declare "page" variable as global then pass as shown in the code

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

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

推荐阅读
author-avatar
只属于我一个人的秘密
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有