Tag: uigesturerecognizer

在代码中的UIButton

我需要添加一个手势(移动,旋转,缩放)到一个UIButton 。 我在代码中创build了button,但是我不知道如何使用它。 如果button被触摸,我想移动,缩放或旋转。 这是我的代码: -(void)addButton{ UIScrollView *scrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(0,0,320,480)]; scrollview.showsVerticalScrollIndicator=YES; scrollview.scrollEnabled=YES; scrollview.userInteractionEnabled=YES; [self.view addSubview:scrollview]; scrollview.contentSize = CGSizeMake(self.view.bounds.size.width,1000.0); buttonImage1 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; buttonImage1.frame = CGRectMake(100, 20, 100, 100); UIImage *btnImage1 = [UIImage imageWithData:[NSData dataWithContentsOfURL: [NSURL URLWithString:adres1]]]; [buttonImage1 setImage:btnImage1 forState:UIControlStateNormal]; [scrollview addSubview:buttonImage1]; buttonImage2 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; buttonImage2.frame = CGRectMake(100, 180, 150, 150); UIImage *btnImage2 = [UIImage imageWithData:[NSData […]

手势识别器和块

我们可以使用手势识别器使用块吗? 它并不是如此。 例如,这不起作用: UITapGestureRecognizer *tapped = [[UITapGestureRecognizer alloc] initWithTarget: self action:^(id sender) { } ]; 我是否缺less某些东西,或者是UIGestureRecognizer类不支持的块?

UITapGestureRecognizer在Swift 3中没有开火

我在自定义的UIViewController有以下代码: let tapDismissTextField = UITapGestureRecognizer(target: self, action: #selector(dismissTap)) func dismissTap() { print("Tap!") } override func viewDidLoad() { super.viewDidLoad() self.view.addGestureRecognizer(tapDismissTextField) self.friendsView.addGestureRecognizer(tapDismissTextField) } 没有“点击!” 线正在打印,所以手势识别器没有开火。 有什么可能出错? 在此控制器中的所有视图中,用户交互已启用。 这个视图控制器embedded在UINavigationController如果有任何帮助的话。

iOS / Swift UIImageView(.jpg)无法识别我的轻拍手势?

当我的图像被点击时,我有一个简单的代码块来播放声音。 但是,当我点击我的图像,水龙头甚至不被识别。 我相信这是真实的,因为在点击图像时,handleTap函数中的println不会打印任何内容。 谁能给我一些见解,问题可能在哪里? var coinSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("wavSampleSound", ofType: "wav")!) var audioPlayer = AVAudioPlayer() override func viewDidLoad() { super.viewDidLoad() loadSound() let gesture = UITapGestureRecognizer(target: self, action: "handleTap:") gesture.delegate = self myImage.addGestureRecognizer(gesture) } func loadSound() { audioPlayer = AVAudioPlayer(contentsOfURL: coinSound, error: nil) audioPlayer.prepareToPlay() } func handleTap(gesture: UITapGestureRecognizer) { let playsSound = self.audioPlayer.play() println("\(playsSound)") } @IBOutlet […]

UITableView滑动手势需要接近完美的准确性

我正在使用自定义UITableViewCell子类的UITableView自定义刷卡事件。 我在头中包含了UIGestureRecognizerDelegate ,并在viewDidLoad:有这个viewDidLoad: UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipe:)]; swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft; swipeLeft.numberOfTouchesRequired = 1; [self.tableView addGestureRecognizer:swipeLeft]; 我的swipeLeft方法看起来像这样: -(void)didSwipe:(UISwipeGestureRecognizer *)recognizer { if (recognizer.state == UIGestureRecognizerStateEnded) { CGPoint swipeLocation = [recognizer locationInView:self.tableView]; NSIndexPath *swipedIndexPath = [self.tableView indexPathForRowAtPoint:swipeLocation]; NSDictionary *clip = [self.clips objectAtIndex:swipedIndexPath.row]; NSLog(@"Swiped!"); } } 这是有点工作,但刷卡必须非常精确。 像几乎不可能的精确。 我几乎通过使用UIPanGestureRecognizer来解决这个问题,但不幸的是,对于使用全局平移手势识别器的全局侧面抽屉组件(对于那些感兴趣的人来说,ECSlidingViewController)并没有很好的解决方法。 有没有办法解决? 任何帮助将不胜感激,因为我一直在search和浏览几个小时寻找解决scheme。

在ScrollView中旋转缩放ImageView?

我有一个UIScrollView有一个缩放UIImageView ,即它实现: – (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { return self.imageView; } 我想添加一个UIRotationGestureRecognizer这个UIRotationGestureRecognizer ,我这样做,如下所示: _rotationGestureRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)]; [self.imageView addGestureRecognizer:_rotationGestureRecognizer]; -(void)rotate:(id)sender { UIRotationGestureRecognizer *rotationGestureRecognizer = [(UIRotationGestureRecognizer*)sender retain]; if(rotationGestureRecognizer.state == UIGestureRecognizerStateEnded) { self.lastRotation = 0.0; return; } CGFloat rotation = 0.0 – (self.lastRotation – rotationGestureRecognizer.rotation); rotationGestureRecognizer.view.transform = CGAffineTransformRotate(rotationGestureRecognizer.view.transform, rotation); self.lastRotation = rotationGestureRecognizer.rotation; [rotationGestureRecognizer release]; } 我只是想知道,甚至可以做到这一点? […]

立即调用UITapGestureRecognizer

我正在试图添加一个UITapGestureRecognizer到一个imageview ,如下所示 let gest=UITapGestureRecognizer(target: self, action: Selector(imgPressed())); gest.delegate=self thalaImg.addGestureRecognizer(gest) 这里是imgPressed函数: func imgPressed() { let alert=UIAlertController(title: "Img", message: "img pressed", preferredStyle: .Alert) let okButton=UIAlertAction(title: "Ok", style: .Default, handler: nil) alert.addAction(okButton) presentViewController(alert, animated: true, completion: nil) } 我在viewdidload添加了3行代码,添加了一个断点并运行了应用程序。我观察到的是,一旦编译器进入第一行,即let gest …,它即使在应用程序启动之前立即调用action方法运行。由于显然window尚未加载,它会抛出下面的警告 警告:尝试呈现其视图不在窗口层次结构中的视图! 我不明白为什么会发生这种情况。有人可以帮我解决这个问题吗? 谢谢

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

我有一个图像视图中的5animation图像,并希望允许用户基于默认ID点击它们,并推到另一个视图。 我试图添加手势点击,但imageview没有检测到。 有人可以给我一些build议吗? 编辑:结束了我没有使用它,我设置了一个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 […]

UIAlertView警报在长按手势识别器中重复三次

我创build了一个应用程序 通过开发它,我用长button显示警报。 这是我的代码: – (IBAction)longPressDetected1:(UIGestureRecognizer *)sender { // label1.text = @"Select Iran to observe its historical data projections "; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Press the blue button (+) to select your region " delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alert show]; } 问题:当我想通过使用cancelIbutton取消UIAlertView,我必须按下这个button三次取消UIAlertView。 这意味着UIAlterview不能被一个媒体取消。 你可以帮我吗?

在视图上限制手势

这是我如何添加手势的观点 – (void)_addPanGestureToView:(UIView *)view { UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(_handlePan:)]; panGesture.delegate = self; panGesture.maximumNumberOfTouches = 1; panGesture.minimumNumberOfTouches = 1; [view addGestureRecognizer:panGesture]; } 一切都运转良好,但手势是在整个看法,我怎么能做一些像手势回应只有一半的看法?