相关疑难解决方法(0)

UIView touchesbegan在动画期间没有响应

我有一个可拖动的类继承UIImageView.当视图没有动画时,拖动工作正常.但是当它动画时它不会响应触摸.动画完成后,触摸再次起作用.但我需要它在触摸时暂停动画并在触摸结束时恢复.我花了一整天研究它,但无法弄清楚原因.

这是我的动画代码.

[UIView animateWithDuration:5.0f 
  delay:0 
  options:(UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction) 
  animations:^{ 
  self.center = CGPointMake(160,240);
  self.transform = CGAffineTransformIdentity;
  }
  completion:nil
];

- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
    NSLog(@"touch");
    CGPoint pt = [[touches anyObject] locationInView:self];
    startLocation = pt;
    [self.layer removeAllAnimations];
    [[self superview] bringSubviewToFront:self];
}
Run Code Online (Sandbox Code Playgroud)

objective-c uiview uiviewanimation

7
推荐指数
1
解决办法
5794
查看次数

在动画 UIView 上点击手势不起作用

我在翻译动画的 UILabel 上有一个点击手势。每当您在动画期间点击标签时,点击手势都没有响应。

这是我的代码:

    label.addGestureRecognizer(tapGesture)

    label.userInteractionEnabled = true
    label.transform = CGAffineTransformMakeTranslation(0, 0)

    UIView.animateWithDuration(12, delay: 0, options: UIViewAnimationOptions.AllowUserInteraction, animations: { () -> Void in
        label.transform = CGAffineTransformMakeTranslation(0, 900)
        }, completion: nil)
Run Code Online (Sandbox Code Playgroud)

手势代码:

func setUpRecognizers() {
    tapGesture = UITapGestureRecognizer(target: self, action: "onTap:")
}
func onTap(sender : AnyObject) {
    print("Tapped")
}
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?谢谢 :)


为 2021 添加的注释:

这些天这很容易,你只需覆盖hitTest。

iphone uiview ios uitapgesturerecognizer swift

6
推荐指数
2
解决办法
5733
查看次数

如何使动画识别器在动画UIImage视图中工作

我在图像视图中有5个动画图像,并希望允许用户根据默认ID点击它们并将其推送到另一个视图.我试图添加手势点击,但imageview没有检测到.

任何人都可以给我一些建议吗?

编辑:最后我没有使用它,我设置了一个UIButton.

谢谢 :)

viewDidLoad中

self.defaultID = [[NSMutableArray alloc] initWithObjects:@"7",@"9",@"11",@"27",@"6",nil];
self.defaultImageCaption = [[NSMutableArray alloc] initWithObjects:@"Ver",@"Green",@"Red",@"CF",@"Dwarf",nil];

//default image
imageViewTop.alpha = 1.0;
imageViewBottom.alpha = 0.0;
imageViewBottom = [[UIImageView alloc] initWithFrame:CGRectMake(0,44,320,367)];
imageViewTop = [[UIImageView alloc] initWithFrame:CGRectMake(0,44,320,367)];

singleDefaultTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleDefaultTap:)];
singleDefaultTap.numberOfTouchesRequired = 1;
imageViewTop.userInteractionEnabled = YES;
[imageViewTop addGestureRecognizer:singleDefaultTap];
imageViewTop.tag = 2000;

UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0,44,320,367)];
[topView addSubview:imageViewTop];
[self.view addSubview:imageViewTop];
[self.view addSubview:topView];
[self.view addSubview:imageViewBottom];

[self nextAnimation]
Run Code Online (Sandbox Code Playgroud)
-(void)nextAnimation{

//picture loop
imageViewTop.image = imageViewBottom.image;
imageViewBottom.image = [imageArray objectAtIndex:[imageArray count] - 1];

[imageArray …
Run Code Online (Sandbox Code Playgroud)

iphone uianimation uigesturerecognizer ios

4
推荐指数
1
解决办法
1976
查看次数