Recepción de mensajes de delegados mientras se desplaza/zoomiza
Frecuentes
Visto 77 veces
0
I have a custom UIView which is a delegate of an another class, that constantly sends messages to it (updating the text of an UILabel). This custom view also has an UIScrollView as a subview. The problem is that, while I pan/pinch the scrollview, no delegate messages are received (only after the interaction has finished).
How could I make it receive messages all the time?
This is how the other class sends messages to it's delegate:
[NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(onTick:)
userInfo:nil
repeats:YES];
- (void)onTick:(NSTimer *)timer {
NSString *label = ...
if ([delegate respondsToSelector:@selector(updateLabelText:)]) {
[delegate updateLabelText:label];
[delegate updateLabelText:label];
}
...
}
2 Respuestas
0
Add a UIPanGestureRecognizer/UIPinchGestureRecognizer to your UIScrollView and listen delegates method:
Regulating Gesture Recognition
– gestureRecognizerShouldBegin:
– gestureRecognizer:shouldReceiveTouch:
Controlling Simultaneous Gesture Recognition
– gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
Respondido 28 ago 12, 09:08
I don't want to add any custom UIGestureRecognizer. I want to rely on the scrollview's default scrolling/zooming behavior. - desarrollador110
0
Usar [[NSRunLoop currentRunLoop] addTimer:timer forMode:UITrackingRunLoopMode];
solves the problem. Thanks @Jens Kilian!
Respondido 28 ago 12, 09:08
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas iphone objective-c cocoa-touch or haz tu propia pregunta.
Multithreading, using Grand Central Dispatch or NSOperation. But be sure to do the UI work in the main thread/queue! - toasted_flakes
Gesture tracking is done in a special run loop mode. How/when does your "other class" sends the delegate messages? If via a timer etc., you may need to add that timer to the appropriate run loop mode. See Apple's NSRunLoop reference & Threading Programming Guide. - Jens Kilian
Thanks @Jens Kilian! You are right! - developer110