我
我在自定义 scrollView 类的 initierScrollView 函数中生成了多个 UIView 对象。我标记了每个对象并将每个对象插入到 NSMutableArray 对象中。比我将 UIPanGestureRecognizer 与每个视图对象相关联。
-(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(10+62*i,10,62,55)];
classementBoutons = [[NSMutableArray alloc] initWithCapacity:40];
[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];
}
现在我正在尝试通过选择通过 Gesture 移动的对象来重用这些对象。我尝试了从 NSMutableArray 中获取每个对象的方法(如头文件下定义的那样),但 Xcode 似乎无法识别它们(没有新动作)。
-(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];
if(recognizer.state == UIGestureRecognizerStateEnded)
{
NSLog(@"voila c'est fait");
[[classementBoutons objectAtIndex:2]setFrame:CGRectMake(50, 50, 100, 100)];
}
}
我不知道为什么插入到 Mutable 数组中的对象被取出后无法识别?
感谢您的回复。
胜利者