Implement custom scaling for UIScrollView

I have a UIScrollView with the requirement that contentSize.height remains the same when scaling. Scaling from 200x100 should lead to the creation of a new contentSize 400x100 instead of 400x200, for example. I would like to make my own drawing while the user zooms out.

I do not think that I can use the usual scalable behavior of UIScrollView to achieve this, so I am trying to collapse myself. (I could just let this do my job and then redraw my content when -scrollViewDidEndZooming: withView: atScale: gets a call, but that would not be very pretty).

I am currently subclassing UIScrollView and trying to do my own scaling when two fingers are on the screen:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    if ([touches count] != 2) {
        [super touchesMoved:touches withEvent:event];
    } else {
     // do my own stuff
    }
}

I thought that redefining the touches of Began: withEvent :, touchhesMoved: withEvent :, touchesEnded: withEvent: and touchesCancelled: withEvent: should work this way, but it doesn't.

The earlier unsuccessful attempt was to put a transparent view on top of the scroll and send touches that didn't interest me to scroll:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    if ([touches count] != 2) {
        [self.theScrollView touchesMoved:touches withEvent:event];
    } else {
     // do my own stuff
    }
}

Any help would be appreciated.

Thank you Thomas

+3
source share
3 answers

, , . , UIScrollView , , -scrollViewDidEndZooming: withView: atScale: . , , .

, . , , 1 . , UIScrollView , UIScrollView .

, , , .

+3

, :

, , touchesBegan: withEvent:, touchesMoved: withEvent:, touchedEnded: withEvent: touchsCancelled: withEvent: , .

? , , if- , , , .

if ([touches count] != 2)

, , , . , , , . ( ) NSSet, .

- , . , UITouch , , , - , , .

, , set multiTouchEnabled:YES

0

, , , , . scrollViewDidEndZooming: withView: atScale .

, , - viewForZoomingInScrollView: , . , , drawRect . , . , .

, , touchBegan: withEvent: touchhesMoved: withEvent: touchhesBegan: withEvent:

0

Source: https://habr.com/ru/post/1719511/


All Articles