1
幫助我請滾動查看哪個圖像在滾動視圖上。檢測滾動視圖上的圖像
- (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中的當前圖像。非常感謝
2012年12月8日04通,如下所示:22:57.761 MyProject的[2948:F803] IP1。 jpg 2012-12-08 04:22:57.804 MyProject [2948:f803] ip1.jpg 2012-12-08 04:22:57.812 MyProject [2948:f803] ip1.jpg 2012-12-08 04:22 :57.826 MyProject [2948:f803] ip1.jpg 2012-12-08 04:22:57.842 MyProject [2948:f803] ip1.jpg 2012-12-08 04:22:57.867 MyProject [2948:f803] ip1。 jpg 2012-12-08 04:22:57.892 MyProject [2948:f803] ip1.jpg 2012-12-08 04 :22:57.907 MyProject [2948:f803] ip2.jpg 爲什麼它表現如此呢? :(我該如何解決 – user1625435
你能告訴我你在哪裏粘貼代碼 –
假設頁面被正確計算應在didScroll功能很好地完成 –