开发者

Making UIScrollView to both scroll and zoom

I am having some troubles making my UIScrollView to exhibit both scrolling and zooming. My class (which sub-classes UIScrollView) has a UIView as a sub-view, and in this sub-view I draw on a CALayer. As soon as the app launches, I can scroll the view, but as soon as I zoom using the pinch gesture, the scrolling feature stops working, and only the zoom works. My code:

bpmGraphView = [[UIView alloc] init];   
//--- configure the scroll-view and add the graph-view as a subview
[self setZoomScale:1.0];
[self setContentSize:CGSizeMake(1000.0, 169.0)];
[self setMultipleTouchEnabled:YES];
[self setScrollEnabled:YES];
self.maximumZoomScale = 20.0;
self.minimumZoomScale = 0.05;
self.clipsToBounds = YES;   
self.delegate = self;   //--- set the scroll-view delegate to self  
[self addSubview:bpmGraphView];

And the delegate method:

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
    return [self bpmGraphView];
}

Any ideas?

EDIT

Some dimensions: My UIScrollView is 320x169 and it is positioned 7 pixels to the right of the left edge of the screen. The (scrollable) UIView inside it should have the same height, but start 30 pixels to the left of the UIScrollView, and end somewhere far to the right - 1000 is just a test number. The sublayer I add to UIView should have the same size and position as it's superview. I 开发者_开发知识库will init the UIView with the proper frame and report any changes in the behavior of the app.


at a first look i just notice a big ContentSize width and a small height... are you sure you need it to be 1000 x (just) 169?

And which are the dimensions of bpmGraphView?

And why don't you init bpmGraphView with a dimension? It's a UIView, you should init it giving it a frame, with initWithFrame:, not just init.

And also: give us the dimension of your UIScrollView, the only dimension you give us is the UIScrollView.contentSize...


Refer this apple sample code, it contains everything about scrollview http://developer.apple.com/library/ios/#samplecode/ScrollViewSuite/Introduction/Intro.html

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜