, [self getRandomPosition] _widthOfBlock .. , .
-(void)createRandomBlock{
UIView * block = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
block.backgroundColor = [UIColor redColor];
block.userInteractionEnabled=YES;
UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(blockTapped:)];
tapGesture.delegate = self;
tapGesture.numberOfTouchesRequired = 1;
tapGesture.numberOfTapsRequired=1;
[block addGestureRecognizer:tapGesture];
[self.view addSubview:block];
}
-(void)blockTapped:(UITapGestureRecognizer*)gesture{
NSLog(@"I am being called?");
UIView * block = (UIView*)[gesture view];
[block removeFromSuperview];
}
:
touchesBegan , ,
-(void)createRandomBlock{
UIView * block = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
block.backgroundColor = [UIColor redColor];
block.userInteractionEnabled=YES;
block.tag = 100;
self.view.userInteractionEnabled =YES;
UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(blockTapped:)];
tapGesture.numberOfTapsRequired=1;
[block addGestureRecognizer:tapGesture];
[self.view addSubview:block];
[UIView animateWithDuration:5.0 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
[block setFrame:CGRectMake(block.frame.origin.x, self.view.frame.size.height-200, block.bounds.size.width, block.bounds.size.height)];
} completion:^(BOOL finished) {
[block removeFromSuperview];
}];
}
-(void)blockTapped:(UITapGestureRecognizer*)gesture{
NSLog(@"I am being called?");
UIView * block = (UIView*)[gesture view];
[block removeFromSuperview];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInView:self.view];
UIView *tempView = [self.view viewWithTag:100];
if ([tempView.layer.presentationLayer hitTest:touchLocation]) {
NSLog(@"call");
[tempView removeFromSuperview];
}
}