gpt4 book ai didi

iphone - 手势识别器委托(delegate) : how to implement touch delegate functions

转载 作者:行者123 更新时间:2023-12-03 21:03:24 25 4
gpt4 key购买 nike

我实际上正在尝试在实现 touchBegan:withEvent 的 customScrollView 类中插入触摸委托(delegate)函数(类型 touchEnded:withEventgestureRecognizers )。 。

当我尝试将识别器对象的委托(delegate)设置为 self 时,我的 SDK 出现一条警告消息,指出“类型 ID 不兼容”。

我知道 GestureRecognizer 的委托(delegate)协议(protocol)不包含此类函数,但我不知道应该触发哪个委托(delegate)才能在自定义 View 中使用上述函数。

非常感谢您的回复

维克多-玛丽

这是我的代码:

@interface TapScrollView : UIScrollView {

// id<TapScrollViewDelegate> delegate;
NSMutableArray *classementBoutons;
int n;
int o;
//UIImageView *bouton;

}
//@property (nonatomic, assign) id<TapScrollViewDelegate> delegate;
//@property (nonatomic, retain) UIImageView *bouton;

//@property (strong, nonatomic) UIPanGestureRecognizer *bouton01pan;

-(id)init;
-(void)initierScrollView;

-(void) createGestureRecognizers;
-(IBAction)handlePanGesture:(UIPanGestureRecognizer*)sender;


@end



#import "TapScrollView.h"


@implementation TapScrollView

//@synthesize bouton;

- (void)setUpBoutonView {
// Create the placard view -- its init method calculates its frame based on its image
//boutonHome *aBoutonMain = [[boutonHome alloc] init];
//self.boutonMain = aBoutonMain;
//[boutonMain setCenter:CGPointMake(200, 200)];
//[self addSubview:boutonMain];
}

- (id) init
{
if (self = [super init])
{
NSLog(@"Classe TapScrollView initiée");
}
return self;
}


-(void)initierScrollView
{
int i;
for (i=0; i<6; i++) {

UIImage *image = [UIImage imageNamed:@"back.png"];
UIImageView *bouton = [[UIImageView alloc] initWithImage:image];
[bouton setTag:i];
[bouton setFrame:CGRectMake(72+20*i,10,62,55)];
[classementBoutons insertObject:bouton atIndex:i];
bouton.userInteractionEnabled = YES;

UIPanGestureRecognizer *recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
recognizer.delegate = self;
[bouton addGestureRecognizer:recognizer];
[self addSubview:bouton];
}
}
//- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
//{
// UITouch *touch = [touches anyObject];
//[super touchesBegan:touches withEvent:event];

// for (o=1; o<6; o++) {
// if ([touch view] == [self viewWithTag:o])
// {
// UIPanGestureRecognizer *recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:[classementBoutons objectAtIndex:o] action:@selector(handlePanGesture:)];
// [[classementBoutons objectAtIndex:o] addGestureRecognizer:recognizer];
// bouton01 = [self viewWithTag:o];
// }
// }

//CGPoint touchPoint = [touch locationInView:self];
//[self animateFirstTouchAtPoint:touchPoint];
// return;
//}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
for (n=0; n<6; n++) {
NSLog(@"touche cancelled");
[[classementBoutons objectAtIndex:n] setFrame:CGRectMake((72+20)*n,10,62,55)];
}


}

//- (id<TapScrollViewDelegate>) delegate {
// return (id<TapScrollViewDelegate>)super.delegate;
//}

//- (void) setDelegate:(id<TapScrollViewDelegate>) aDelegate
//{
// super.delegate = aDelegate;
//}

#define GROW_ANIMATION_DURATION_SECONDS 0.15
#define SHRINK_ANIMATION_DURATION_SECONDS 0.15



-(IBAction)handlePanGesture:(UIPanGestureRecognizer*)recognizer
{
NSLog(@"Mouvement ok");
CGPoint translation = [recognizer translationInView:self];
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x,
recognizer.view.center.y + translation.y);
[recognizer setTranslation:CGPointMake(0, 0) inView:self];

}
@end

最佳答案

尝试指定:

@interface TapScrollView : UIScrollView <UIGestureRecognizerDelegate> {

这样,你的警告应该就会消失,尽管我不得不承认我还没有完全清楚你想要完成什么,所以可能还有其他问题。

关于iphone - 手势识别器委托(delegate) : how to implement touch delegate functions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11281251/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com