Scrollview mit Buttons scrollt nicht bei touch auf Buttons

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • macmoonshine schrieb:

    Thallius schrieb:

    Hm, verstehe ich nicht. Bei mir geht es aber doch problemlos?

    Gib mal dem Button eine andere Farbe für den Zustand highlighted. Sobald der Button beim Drücken in diesen Zustand wechselt, kannst Du nicht mehr scrollen.


    ja klar, aber dasdauert doch auch fast 1s bis es soweit ist. Damit ist doch klar abgegrenzt ob ich scrollen oder klcken will. Warum solte ich dann noch scrollen wollen. Das würde ich nicht versuchen irgendwie hinzufuschen. Da hat sich Apple sicher was bei gedacht und ich selber finde es auch gut so.

    Gruß

    Claus
    2 Stunden Try & Error erspart 10 Minuten Handbuchlesen.

    Pre-Kaffee-Posts sind mit Vorsicht zu geniessen :)
  • Ich habe mich für den UIImageView Ansatz entschieden. Hier der Code, falls jemand einmal in der selben Situation ist.

    Quellcode

    1. // im ViewController
    2. - (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    3. {
    4. UITouch *touch = [touches anyObject];
    5. self.startpoint = [touch locationInView:self.scrollView];
    6. self.layerMoved = NO;
    7. }
    8. - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    9. {
    10. self.layerMoved = YES;
    11. }
    12. - (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
    13. {
    14. UITouch *touch = [touches anyObject];
    15. CGPoint point = [touch locationInView:self.scrollView];
    16. if (abs(point.x-self.startpoint.x) > 20) {
    17. self.layerMoved = YES;
    18. }
    19. if (!self.layerMoved) {
    20. for (UIImageView *item in self.pageViews) {
    21. if ([item isKindOfClass:[UIImageView class]]) {
    22. if (CGRectContainsPoint(item.frame, point)) {
    23. [self performSegueWithIdentifier:@"ToWorldPeace" sender:self];
    24. }
    25. }
    26. }
    27. }
    28. }
    Alles anzeigen


    Das macht noch eine Unterklasse von Scrollview notwendig, die eigene Touch Methoden besitzt:

    Quellcode

    1. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    2. {
    3. [self.superview touchesBegan:touches withEvent:event];
    4. }
    5. - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
    6. {
    7. [self.superview touchesEnded:touches withEvent:event];
    8. }
    9. - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    10. {
    11. [self.superview touchesMoved:touches withEvent:event];
    12. }
    Alles anzeigen


    Vielen Dank nochmal. :D