我有一个scrollview。它表现为滑块。(从左到右,从右到左)。如果我向左滑动或向右滑动,则可以正常工作。没问题。但是,如果我首先长按,然后我尝试向左或向右滑动,它就不起作用。
- (void)initCarouselScroll
{
[self.carouselScroll removeFromSuperview];
self.carouselScroll = nil;
self.carouselScrollHeight = self.view.frame.size.height;
self.carouselScrollWidth = self.view.frame.size.width;
self.carouselScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.carouselScrollWidth, self.carouselScrollHeight)];
self.carouselScroll.backgroundColor = [UIColor clearColor];
self.carouselScroll.autoresizingMask = UIViewAutoresizingFlexibleWidth;
self.carouselScroll.tag = 500;
self.carouselScroll.showsHorizontalScrollIndicator = NO;
self.carouselScroll.directionalLockEnabled = YES;
self.carouselScroll.showsVerticalScrollIndicator = NO;
self.carouselScroll.pagingEnabled = YES;
self.carouselScroll.delegate = self;
self.carouselScroll.contentSize = CGSizeMake(self.carouselScrollWidth * [self.bannerList count], self.carouselScrollHeight);
[self.carouselScroll setContentOffset:CGPointZero];
[self.view addSubview:self.carouselScroll];
[self.view sendSubviewToBack:self.carouselScroll];
NSUInteger maxLoad = 3;
if ([self.bannerList count] < maxLoad) {
maxLoad = [self.bannerList count];
}
for (int i = 0; i < maxLoad; i++) {
[self loadImageFor:i];
}
[self updateSelectedDotImage:0];
}
- (void)loadImageFor:(int)index
{
if (index < 0 || index >= [self.bannerList count]) {
return;
}
AnyImageView* imageView = (AnyImageView*)[self.carouselScroll viewWithTag:index];
if (!imageView) {
Banner* banner = [self.bannerList objectAtIndex:(index)];
CGRect frame = CGRectMake(self.carouselScrollWidth * (index), 0, self.carouselScrollWidth, self.carouselScrollHeight);
NSString* imageUrl = banner.iphoneImage;
if (self.deviceType == DeviceTypeIpad) {
imageUrl = banner.ipadImage;
}
AnyImageView* imageView = [[AnyImageView alloc] initWithFrame:frame picPath:imageUrl isWhite:NO];
imageView.tag = index;
UITapGestureRecognizer* singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(bannerButtonClicked:)];
UILongPressGestureRecognizer* longTap = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressGestures:)];
UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addGestureRecognizer:singleTap];
[button removeGestureRecognizer:longTap];
button.frame = frame;
button.tag = index;
button.backgroundColor = [UIColor clearColor];
[self.carouselScroll addSubview:imageView];
[self.carouselScroll addSubview:button];
}
}