UIControl Nicht Empfangen Berührt

Habe ich ein UIControl, das die Berührungen begann die Methode so auf:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
    //More code goes here

Dieser Unterklasse von UIControl ist instanziiert in einer view-controller, es wird dann Hinzugefügt, als eine Untersicht auf, dass view-controller. Ich habe einen Haltepunkt an der berührt, begann die Methode der UIControl, und die Methode nie aufgerufen wird. Ich habe etwas Lesen und es scheint, dass die View-Controller hat eine gewisse Logik, die entscheidet, ob der pass auf touch-events auf die Untersichten. Das merkwürdige ist, dass ich eine andere Unterklasse von UIControl in der gleichen view-controller, und die touch-Ereignisse get weitergegeben wird, wenn der Benutzer Sie berührt!
Hier ist der vollständige code:

.h

#import <UIKit/UIKit.h>

@interface CustomSegment : UIView
@property (nonatomic, strong) UIImageView *bgImageView;
@property (nonatomic, assign) NSInteger segments;
@property (nonatomic, strong) NSArray *touchDownImages;
@property (nonatomic, readonly, assign) NSInteger selectedIndex;
@property (nonatomic, weak) id delegate;


- (id)initWithPoint:(CGPoint)point numberOfSegments:(NSInteger)_segments andTouchDownImages:(NSArray *)_touchDownImages;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
@end

.m

#import "CustomSegment.h"

@implementation CustomSegment
@synthesize bgImageView, segments, touchDownImages, selectedIndex, delegate;

- (id)initWithPoint:(CGPoint)point
   numberOfSegments:(NSInteger)_segments
           andTouchDownImages:(NSArray *)_touchDownImages  
{  
    self = [super initWithFrame:CGRectMake(point.x, point.y, [[_touchDownImages     objectAtIndex:0] size].width, [[touchDownImages objectAtIndex:0] size].height)];
if (self)
{
    touchDownImages = _touchDownImages;
    segments = _segments;
    bgImageView = [[UIImageView alloc] initWithImage:[touchDownImages objectAtIndex:0]];
    [self addSubview:bgImageView];
}
return self;
}

- (BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
{
    return YES;  
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    //[super touchesBegan:touches withEvent:event];
    UITouch *touch = [touches anyObject];
    float widthOfSegment = [self frame].size.width / segments;
    float bottomPoint = 0;
    float topPoint = widthOfSegment;
    for (int i = 0; i < segments; i++)
    {
        if ([touch locationInView:self].x > bottomPoint && [touch locationInView:self].x < topPoint)
        {
            [bgImageView setImage:[touchDownImages objectAtIndex:i]];
            selectedIndex = i;
            return;
        }
        else
        {
            bottomPoint = topPoint;
            topPoint += topPoint;
        }
    }
}
@end
Wie fügen Sie die beiden UIControll sunbviews? Können Sie zeigen einige code?
Die Lösung ist in einer doppelten thread hier durch 'jhabbot' stackoverflow.com/questions/1245248/...

InformationsquelleAutor Kyle Rosenbluth | 2012-02-19

Schreibe einen Kommentar