开发者

Create a scrollable menu with UIImages representing each possible selection. These UIImages must be able to snap to the grid one by one

I'm trying to create a menu (using UIScrollView) where the user can select images (using UIImageViews).

I intend to have at least 3 images visible at anytime. When I scrol开发者_开发百科l, the images will be able to snap into position.

However, if I am to use a UIScrollView which is large enough to display 3 images at anyone time, and I enable paging, the paging will move all 3 images together and snap only at the next 3 images.

And if I am to use UIScrollView that fits just 1 image, and I enable clipsToBounds (which helps me draw the images beyond the boundary of the UIScrollView). My figure gestures can only be detected within UIScrollView itself, I want my figure gestures to be detected as long as any of the images are touched.

Thanks.


You can use following method of UIScrollView to scroll it from code as much as you want.

- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated

you can call this from following method of UIScrowViewDelegate. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

Thus, you can manage how much you scroll view will call.

And for getting touches, implement a separate class that display images(inherit it from UIImageView or UIView) and implement touchesBegin or touchesEnded in that. Here when you get the touch in your custom view call some method of parent view and notify it with proper arguments(you can assign tag property and pass it to scroll view to find exactly which image was tapped).

.....I am not sure weather I am solving your problem or not.....so post here if you need any further assistance.


I wrote a custom UIView class which overrides the hitTest method of UIView.

In the header of the custom UIView class, declare a UIScrollView, later you will need to assign the UIScrollView which is displaying the menu to this variable.

UIScrollView *thatScrollView;

In the implementation, remember to synthesize the variable and overwrite hitTest

@synthesize thatScrollView;

- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    if ([self pointInside:point withEvent:event]) {
        return thatScrollView;
    }
    return nil;
}

Then in the UIViewController class, create an instance of the class and assign the scrollview you want to scroll:

hiddenView.underneathButton = scrollView1;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜