1
votes

I create many subviews inside a UIScrollView. Let me call each subview a Cell. Each cell has a UILabel in it.

Then I implement touchEnd method on the Cell class, hoping that my app will respond to my touch whenever I tap on any of the cells. However I am not able to get response from all Cells. I can only get responses from the Cells that are above the bottom of my phone (iPhone 5 is 568 something) in the ScrollView whereas the contentsize of my ScrollView is 2300 * 1000, which means those cells below y = 568 don't respond to my touches. How can I fix this? Here is my touchEnd method in Cell class

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    if (![self.unit.text isEqualToString:@"?"]) {
        [self.soundManager playSoundForUnit:self.unit];
    }
}
1
Try my answer...it will work - Samkit Jain

1 Answers

0
votes

You have to make CustomScrollView :

.h :

@protocol CustomScrollViewDelegate <NSObject>

@optional
// optional becuase we always don't want to interact with ScrollView

- (void) customScrollViewTouchesEnded :(NSSet *)touches withEvent:(UIEvent *)event;

@end

@interface CustomScrollView : UIScrollView

@property (weak, nonatomic) id<CustomScrollViewDelegate> touchDelegate;
// delegate was giving error becuase name is already there in UIScrollView 

@end

.m :

#import "CustomScrollView.h"

@implementation CustomScrollView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{

    if (!self.dragging) {
        //NSLog(@"touchesEnded in custom scroll view");
        if (_touchDelegate != nil) {
            if ([_touchDelegate respondsToSelector:@selector(customScrollViewTouchesEnded:withEvent:)]) {
                [_touchDelegate customScrollViewTouchesEnded:touches withEvent:event];
            }
        }
    }

    else {
        // it wouldn't be called becuase at the time of dragging touches responding stops.
        [super touchesEnded:touches withEvent:event];
    }

}

@end