Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 当UIButton在动画中移动时,如何允许触摸它?_Ios_Objective C_Animation_Uibutton_Jquery Animate - Fatal编程技术网

Ios 当UIButton在动画中移动时,如何允许触摸它?

Ios 当UIButton在动画中移动时,如何允许触摸它?,ios,objective-c,animation,uibutton,jquery-animate,Ios,Objective C,Animation,Uibutton,Jquery Animate,这是我的密码: [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:100]; [UIView setAnimationRepeatCount:1000]; [UIView setAnimationRepeatAutoreverses:NO]; [UIView setAnimationBeginsFromCurrentState:YES]; CGFloat x = (CGFloat) (arc4rando

这是我的密码:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:100];
[UIView setAnimationRepeatCount:1000];
[UIView setAnimationRepeatAutoreverses:NO];
[UIView setAnimationBeginsFromCurrentState:YES];

CGFloat x = (CGFloat) (arc4random() % (int) self.view.bounds.size.width);
CGFloat y = (CGFloat) (arc4random() % (int) 463);

if(y < 90)
    y = 90;

if(x > 270)
    x = 270;

CGPoint squarePostion = CGPointMake(x, y);

button.center = squarePostion;

[UIView setAnimationDelegate:self];
[UIView commitAnimations];
[UIView beginAnimations:nil context:nil];
[UIView设置动画持续时间:100];
[UIView setAnimationRepeatCount:1000];
[UIView setAnimationRepeatAutoreverses:否];
[UIView setAnimationBeginsFromCurrentState:是];
CGFloat x=(CGFloat)(arc4random()%(int)self.view.bounds.size.width);
CGFloat y=(CGFloat)(arc4random()%(int)463);
如果(y<90)
y=90;
如果(x>270)
x=270;
CGPoint squareposition=CGPointMake(x,y);
button.center=方形位置;
[UIView setAnimationDelegate:self];
[UIView委员会];

我知道我需要在某处添加“UIViewAnimationOptionAllowUserInteraction”,但我如何才能做到这一点?

这在动画制作过程中对我很有效。希望也会对你有用。
在动画期间将按钮对象添加到阵列中,并在动画完成后将其删除

[self.arrBtn addObject:btn];

[self.view addSubview:btn];
[self.view bringSubviewToFront:btn];

[UIView animateWithDuration:8.0f
                      delay:0.0f
                    options:UIViewAnimationOptionAllowUserInteraction
                 animations:^{
                     btn.frame = CGRectMake(endX, 500.0, 50.0 * scale, 50.0 * scale);
                 }
                 completion:^(BOOL finished){

                     [self.arrBtn removeObject:btn];

                 }]; 


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInView:self.view];
for (UIButton *button in self.arrBtn) // arrBtn is array of button
{
    if ([button.layer.presentationLayer hitTest:touchLocation])
    {
        // This button was hit whilst moving - do something with it here

        NSLog(@"Button Clicked");
        break;
    }
}
}

在动画期间将按钮对象添加到阵列,并在动画完成时从中删除。谢谢!虽然我正在“break;”之前执行选择器,但这是可行的只有当我的手指一直按在屏幕上时,它才会起作用-这是为什么?我正在使用
[自执行选择器:@selector(tapAvatar:)with object:button afterDelay:0][btn addTarget:self action:@selector(btnClicked:)for ControlEvents:UIControlEventTouchUpInside];使用这个,但我们回到原点,它不会被称为:(对不起,你说的方格是什么意思?