Domanda

I have implemented the iCarousels in my project. But after updating the app for iOS 7, my iCarousels are getting stuck in between. Its working fine in iOS 6 and 5. the problem in iOS 7 is that my scroll view below the iCarousel view is getting called first sometimes when I touch my carousel view. Can anyone help me out here?

Is the solution in the following method's return value:

- (CGFloat)carouselItemWidth:(iCarousel *)carousel

I tried many things here, and it works fine for few times, and again after some time it start getting stuck because the scroll view takes the touch from its subview(iCarousel view) and call its own delegate methods before the iCarousel's delegate method.

I am not using any gesture recognizer. I am using scroll view because i have iCarousel view and another view resting on UIScrollView, so that I can use pull to refresh as well.

The following delegate methods I am using, and changing in carouselItemWidth has decreased the stuck problem, but it still persists

- (CATransform3D)carousel:(iCarousel *)carousel itemTransformForOffset:(CGFloat)offset     baseTransform:(CATransform3D)transform
{
CGFloat tilt = 0.65f;
CGFloat spacing = 0.28f; // should be ~ 1/scrollSpeed;
CGFloat clampedOffset = fmaxf(-1.0f, fminf(1.5f, offset));
CGFloat itemWidth = 320;

CGFloat x = (clampedOffset * 0.5f * tilt + offset * spacing) * itemWidth;
CGFloat z = fabsf(clampedOffset) * -itemWidth * 0.5f;

transform = CATransform3DTranslate(transform, 0.0f, x, z);
transform = CATransform3DRotate(transform, -clampedOffset * M_PI_2 * tilt, -1.0f, 0.0f,   0.0f);

//DLog(@"offset: %f, %@", offset, [NSValue valueWithCATransform3D:transform]);

return transform;
}

- (NSUInteger)numberOfPlaceholdersInCarousel:(iCarousel *)carousel
{

//note: placeholder views are only displayed on some carousels if wrapping is disabled

return 0;

}

- (CGFloat)carouselItemWidth:(iCarousel *)carousel
{
//usually this should be slightly wider than the item views


if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
{
    return 270;
}
else
{
    return 250;
}
}



- (BOOL)carouselShouldWrap:(iCarousel *)carousel
{
return NO;
}
È stato utile?

Soluzione

The problem seems to be that when a scrollview receives a touch, it waits a second to see if it should handle it before passing it to the carousel.

You can (mostly) fix this by setting scrollView.delaysContentTouches = NO;

It's still a bit clunky if you try to swipe the carousel when the scrollview is moving/decelerating however. You will have to wait until it stops moving to interact with the carousel.

I'm investigating if there's a better way to fix this.

UPDATE:

I still don't have a proper general-purpose fix for this yet, but as a workaround, you can add this method to your local copy of iCarousel:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gesture shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return [gesture isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
}

This forces iCarousel's pan gesture recogniser to take precedence over the one in the scrollView. If you combine this with the delaysContentTouches fix above, you shouldn't have any issues scrolling the carousel when it's inside a tableview or scrollview.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top