簡體   English   中英

UIImage無法檢測到觸摸

[英]UIImage can not detect touch

我使用下面的代碼來檢測UIImage的觸摸

//

#import <UIKit/UIKit.h>

@interface KUIImageView : UIImageView
{


        CGPoint startLocation;
}
@end


@implementation KUIImageView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
    // Retrieve the touch point
    CGPoint pt = [[touches anyObject] locationInView:self];
    startLocation = pt;
    [[self superview] bringSubviewToFront:self];
}
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {
    // Move relative to the original touch point
    CGPoint pt = [[touches anyObject] locationInView:self];
    CGRect frame = [self frame];
    frame.origin.x += pt.x - startLocation.x;
    frame.origin.y += pt.y - startLocation.y;
    [self setFrame:frame];
}



@end

我將觸碰點設置為斷點

但這不是觸發

UIImage通過使用在UIScrollView上

[aScrollView addObject:aUIImageView];

歡迎任何評論

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // here
        self.userInteractionEnabled = YES;
    }
    return self;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM