UIScrollview with UIButtons - how to recreate springboard?

后端 未结 7 1530
鱼传尺愫
鱼传尺愫 2020-11-30 20:41

I\'m trying to create a springboard-like interface within my app. I\'m trying to use UIButtons added to a UIScrollView. The problem I\'m running in to is with the buttons no

7条回答
  •  庸人自扰
    2020-11-30 20:55

    I have a similar case that a number of buttons on a UIScrollView, and I want to scroll these buttons. At the beginning, I subclassed both UIScrollView and UIButton. However, I noticed that my subclassed UIScrollView did not receive touchesEnded event, so I changed to only subclass UIButton.

    
    @interface MyPhotoButton : UIButton {
    }
    
    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
    - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
    @end
    
    
    @implementation MyPhotoButton
    
    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
        [super touchesMoved:touches withEvent:event];
        [self setEnabled:NO];
        [self setSelected:NO];
    }
    
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
        [super touchesEnded:touches withEvent:event];
        [self setEnabled:YES];
    }
    
    - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
        [super touchesCancelled:touches withEvent:event];
        [self setEnabled:YES];
    }
    
    @end
    

提交回复
热议问题