我
我在自定义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];
}
现在我正在尝试通过选择正在移动手势的对象来重用对象。我尝试了从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数组的对象在从它中被抓出后无法识别?
感谢您的回复。
维克多