uitapaddgesturerecognizerr xib怎么连线

本周问答荣誉榜
本月问答荣誉榜
含有标签"GestureRecognizer"的问题
& &self.navigationController.interactivePopGestureRecognizer.delegate =
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
& & if (self.navigationController.viewControllers.count == 1)//关闭主界面的右滑返回
& & return NO;
& & }else{
& & & & return YES;
在主viewcontroller里面加了第一句以后,返回会出现这样的问题
respondsToSelector:]: message sent to deallocated instance 0x15cf4990
不知道是什么原因,这个崩溃是偶尔出现的,不是每次都崩...
如何使用纯代码操作,为一个ImageView添加一个gestureRecognizer?
利用UISwipeGestureRecognizer手势自定义cell滑动删除。该怎么做啊。求大神赐教!!!!!
我想在进入二级界面后,禁用某一个全局的UIPanGestureRecognizer手势。
在一级界面时,这个手势可以通过右横滑打开左侧的抽屉菜单,现在我想在进入二级界面后禁用这个手势。
我在一个uiview上加了一个tableview,uiview有点击事件:
UITapGestureRecognizer *TapGesturRecognizer =
& & [[UITapGestureRecognizer alloc] initWithTarget:self
& & & & & & & & & & & & & & & & & & & & & & action:@selector(actMore:)];
& &&[self.subOrder addGestureRecognizer:TapGesturRecognizer];
点击tableviewcell的时候没有响应,怎么让uiview的点击事件和tableview的不冲突。...
我在cellForRowAtIndexPath中给每个cell添加长按功能,但是其中一个不能有长按功能,我用的是底下的代码(其中一部分)。但是不起作用,请大神指导下。
-(UITableViewCell *) tableView:(UITableView *)theTableView&
cellForRowAtIndexPath:(NSIndexPath *)indexPath
& & UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
& & & & & & & & & & & & & & & & & & & & & & & &initWithTarget:self action:@selector(handleLongPressPreview:)];
& & //设置长按时间
& & longPress.minimumPressDuration=LONGPRESSTIME2;
& & [signalCell addGestureRecognizer:longPress];
& & [longPress release];
&&&&if(条件)
&&&&&&&&& &[signalCell removeGestureR...
我想实现这样一个效果,对于一个屏幕上的一个subView,只能水平向左移动,禁止其他方向的移动,同时如果向左移动的幅度小于某个阈值,则视图将以动画的形式回退到起始位置,而如果左移的幅度达到阈值,则视图停止在该位置,另外左移幅度不能大于该阈值
我想使用panGesture来实现该效果,为此我通过打印输出的方式看了gesture的几种状态,我发现每次滑动都是如下一个状态变化的序列,首先是一个UIGestureRecognizerStateBegan, 然后是若干个&UIGestureRecognizerStateChanged, 最后是一个&UIGestureRecognizerStateEnded。
为此我写了如下代码
-(void)fingerMoved:(UIPanGestureRecognizer *)gestureRecognizer
& & CGPoint startP
& & CGPoint endP
& & if(gestureRecognizer.state == UIGestureRecognizerStateBegan)
& & & & startPos = testGestureView.
& & & & endPos = testGestureView.
怎么在一个XIB文件里面添加一个手势 能同时用于识别多个控件,我想在xib中添加一个 tab手势,用于多个UILable控件,现在的情况是 只能识别了一个,请问在xib中里面怎么设置 ,求大神解答
我的程序里用UILongPressGestureRecognizer,但是如果直接点在view上不动,不会响应手势,只有稍微移动一下才会响应,请问有人遇到过这样的问题吗?应该怎么解决?
以下是我添加手势的代码
UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressFrom:)];
&[pressView addGestureRecognizer:longPressRecognizer];
#define CellKey @"Cell"
在tableview的cellForRowAtIndexPath里添加的手势
UILongPressGestureRecognizer *longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] init];
& & [longPressGestureRecognizer addTarget:self action:@selector(gestureRecognizerHandle:)];
& & [longPressGestureRecognizer setMinimumPressDuration:1.0f];
& & [longPressGestureRecognizer setValue:cell forKey:CellKey];
& & [cell addGestureRecognizer:longPressGestureRecognizer];
在[longPressGestureRecognizer&setValue:cell&forKey:CellKey];这句话报
'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key Cell.'
view中加了很多gesture,能否根据某个关键字删除某个gesture,比如不小心在代码的某些地方重复生成同一类型的gesture,生成时传的参数都一样,希望删除某个gesture的时候将这些相同的gesture都删除了?
遇到一个问题,屏幕上有个提示框,然后我想实现除了那个框之外的所有区域都能响应手势,应该如何确定区域的范围,另外因为之前代码的原因,这个框是在window对象上的,而我所能点击的区域可能在其他view上。所以不能通过subView来进行区分,哪位大侠可以给个解决的思路,谢谢!
-(void)viewWillAppear:(BOOL)animated{
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
& & & & tapGestureRecognizer.numberOfTapsRequired = 1;
& & & & tapGestureRecognizer.numberOfTouchesRequired = 1;
[self.groupView&addGestureRecognizer:tapGestureRecognizer];
////// 断点定在以下这个方法,根本没有进入方法里。
-(void)tap:(UITapGestureRecognizer*)tapGestureRecognizer{
& & NSLog(@"============= Fuck ==============");
今天刚刚发现给tableviewcell添加长按手势后,每次长按cell时,长按手势对应的方法会被执行两次&
代码如下 &就是这个longPressedAct函数 &每次都会执行两次 这个执行次数可以控制吗 有哪位朋友能解释一下&
UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CustomCellIdentifier];
& & cell.textLabel.text = @"hello world";
& & UILongPressGestureRecognizer *longPressed = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressedAct:)];
& & longPressed.minimumPressDuration = 1;
& & [cell.contentView addGestureRecognizer:longPressed];
-(void)longPressedAct:(id)sender{
//& & if (tabFlag == 0) {
//& & & & NSLog(@"12121");
//& & & & tabFlag = 1;
//& & } else {
//& & & & tabFlag = 0;
双页的UIPageViewController左右页分别有两个TableView&UIPageViewController的Pan 手势 与&TableView的Pan手势冲突,请问该如何处理?
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController{
& & if (_isShowDetail) {
& & & & NSUInteger index = [self indexOfViewController:(PoemDetailPageContentViewController *)viewController];
& & & & if (index == NSNotFound) {
& & & & & &
& & & & index++;
& & & & if (index == [self.poemdetailPageContent count]) {
& & & & & & showAlertView(@"已经是最后一首了");
& & & & & &
& & & & ret...默认情况下,有以下控件已经支持UIMenuController
   UITextField
   UITextView
   UIWedView
以UITable为例,说明点击后弹出复制剪切粘贴等为例  
使用的整体思路:(系统自带的文字)
1、新建一个UILabel的类,如果想以后storyboard和Xib都可以用,就可以调用awakeFromNib和initWithFrame方法,同时进行初始化操作
2、使UILabel成为第一响应者作用:
    提供两种方法BecomeFirstResponder和canPerformAction(两种必写)
& & & & & & 同时告诉UIMenuController支持哪些操作,这些操作如理。
3、创建UIMenuController对象,设置两个条件
首先:设置弹出的对象显示的范围
然后:让对象能够显现出来,且动画方式出现
4、UIMenuController对象的各类方法操作的实现(copy,paste,cut等)
1 #import "ZWLabel.h"
3 @implementation ZWLabel
5 - (void)awakeFromNib
[self setup];
9 - (type)initWithFrame:(CGRect)frame
if (self = [super initWithFrame:frame]) {
[self setup];
初始化操作
19 - (void)setup
self.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelClick)];
[self addGestureRecognizer:tap];
点击后操作
28 - (void)labelClick
//使之成为第一响应者,成为之后会提供两种方法becomeFirstResponder和canPerformAction
//同时告诉UIMenuController支持哪些操作,这些操作如何处理
[self becomeFirstResponder];
//创建menu控制器
UIMenuController *menu = [UIMenuController sharedMenuController];
//弹出的menu显示在哪个区域(两种方式)
[menu setTargetRect:self.frame inView:self.superview];
[menu setTargetRect:self.bounds inView:self];
//使menu可见
[menu setMenuVisible:YES animated:YES];
是label能成为第一响应者
46 - (BOOL)canBecomeFirstResponder
return YES;
label能执行哪些操作(比如copy,paste)
54 - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
NSLog(@"%@",NSStringFromSelector(action));//此处可以打印出支持哪些操作(比如copy,cut,paste等,详情见最底部的打印结果)
if (action == @selector(copy:) || action == @selector(cut:) || action == @selector(paste:)) return YES;
return NO;
61 - (void)copy:(UIMenuController *)menu
//将自己的文字复制到粘贴板
UIPasteboard *board = [UIPasteboard generalPasteboard];
board.string = self.
67 - (void)cut:(UIMenuController *)menu
//将自己的文字复制到粘贴板
[self copy:menu];
//清空文字
self.text =
74 - (void)paste:(UIMenuController *)menu
UIPasteboard *board = [UIPasteboard generalPasteboard];
self.text = board.string;
整体都需要移动到viewController中,否则虽然都在UILabel中,能正确运行,但是会提示一堆警告。
即不用重新新建一个继承自UILabel的类,只需要添加了一个UIMenuItem对象,去除掉canPerformAction以及相关的方法即可,代码如下:
注意:需要在label中勾上userInteractionEnabled
1 #import "ViewController.h"
2 @interface ViewController ()
3 @property (weak, nonatomic) IBOutlet UILabel *textL
7 @implementation ViewController
9 - (void)viewDidLoad {
[super viewDidLoad];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelClick)];
[self.textLabel addGestureRecognizer:tap];
点击后操作
18 - (void)labelClick
//使之成为第一响应者,成为之后会提供两种方法becomeFirstResponder和canPerformAction
//同时告诉UIMenuController支持哪些操作,这些操作如何处理
[self.textLabel becomeFirstResponder];
//创建menu控制器
UIMenuController *menu = [UIMenuController sharedMenuController];
//弹出的menu显示在哪个区域
[menu setTargetRect:self.frame inView:self.superview];
[menu setTargetRect:self.textLabel.bounds inView:self.textLabel];
//使menu可见
[menu setMenuVisible:YES animated:YES];
//自定义menuItem
UIMenuItem *ding = [[UIMenuItem alloc] initWithTitle:@"顶" action:@selector(ding:)];
UIMenuItem *replay = [[UIMenuItem alloc] initWithTitle:@"回复" action:@selector(replay:)];
UIMenuItem *report = [[UIMenuItem alloc] initWithTitle:@"举报" action:@selector(report:)];
menu.menuItems = @[ding,replay,report];
40 - (void)ding:(UIMenuController *)menu
NSLog(@"%s
%@",__func__,menu);
44 - (void)replay:(UIMenuController *)menu
NSLog(@"%s
%@",__func__,menu);
48 - (void)report:(UIMenuController *)menu
NSLog(@"%s
%@",__func__,menu);
52 - (BOOL)canBecomeFirstResponder
return YES;
支持的系统自带的各类方法:
1 2016-07-13 22:34:35.099 UIMenuController[16825:1745455] cut:
2 2016-07-13 22:34:35.100 UIMenuController[16825:1745455] copy:
3 2016-07-13 22:34:35.100 UIMenuController[16825:1745455] select:
4 2016-07-13 22:34:35.100 UIMenuController[16825:1745455] selectAll:
5 2016-07-13 22:34:35.100 UIMenuController[16825:1745455] paste:
6 2016-07-13 22:34:35.100 UIMenuController[16825:1745455] delete:
7 2016-07-13 22:34:35.100 UIMenuController[16825:1745455] _promptForReplace:
8 2016-07-13 22:34:35.100 UIMenuController[16825:1745455] _transliterateChinese:
9 2016-07-13 22:34:35.101 UIMenuController[16825:1745455] _showTextStyleOptions:
10 2016-07-13 22:34:35.101 UIMenuController[16825:1745455] _define:
11 2016-07-13 22:34:35.101 UIMenuController[16825:1745455] _addShortcut:
12 2016-07-13 22:34:35.101 UIMenuController[16825:1745455] _accessibilitySpeak:
13 2016-07-13 22:34:35.101 UIMenuController[16825:1745455] _accessibilitySpeakLanguageSelection:
14 2016-07-13 22:34:35.101 UIMenuController[16825:1745455] _accessibilityPauseSpeaking:
15 2016-07-13 22:34:35.102 UIMenuController[16825:1745455] _share:
16 2016-07-13 22:34:35.102 UIMenuController[16825:1745455] makeTextWritingDirectionRightToLeft:
17 2016-07-13 22:34:35.102 UIMenuController[16825:1745455] makeTextWritingDirectionLeftToRight:加载带有手势识别器的XIB文件需注意哪些问题
生活已是百般艰难,为何不努力一点。下面图老师就给大家分享加载带有手势识别器的XIB文件需注意哪些问题,希望可以让热爱学习的朋友们体会到设计的小小的乐趣。
如果在你的应用程序中需要检测手势,比如点击(tap)、二指拨动 (pinch)、拖移(pan)和旋转(rotation),那么通过创建UIGestureRecognizer类来实现将十分简单。接下来图老师小编给大家分享加载带有手势识别器的XIB文件需主要的问题。首先新建一个继承自UIView的类,并创建相应的XIB文件#import
ZHDemoView : UIView+ (instancetype)demoV@end提供一个类方法以供快速创建当前类在.m中实现类方法,通常从XIB中加载出来的是一个数组,所以用到了lastObject方法+ (instancetype)demoView{ NSArray *nibArray = [[NSBundle mainBundle] loadNibNamed:@"ZHDemoView" owner:nil options:nil]; return [nibArray lastObject];}  在awakeFromNib中添加相应的手势- (void)awakeFromNib{ UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click)]; [self addGestureRecognizer:tap];}- (void)click{ NSLog(@"%s", __func__);}另外,测试用的XIB长这样:在根控制器添加一个这样的View,运行并点击结果是 13:44:44.988 XIB注意[] -[ZHDemoView click]一切正常,接下来我们不在代码中添加手势,直接在XIB中添加(之前添加手势的代码已清除):运行结果: 14:02:12.747 XIB注意[] -[UITapGestureRecognizer superview]: unrecognized selector sent to instance 0x7fe47af49c60可以看到是消息发送错误,UITapGestureRecognizer中没有superview方法。回到这张图我们可以看到Objects栏下方有手势识别器和DemoView两个对象,那么是否有可能是因为XIB加载的对象错误呢?因为之前提供的类方法中我们使用的是lastObject方法,这次我们使用firstObject试一试更改类方法如下:+ (instancetype)demoView{ NSArray *nibArray = [[NSBundle mainBundle] loadNibNamed:@"ZHDemoView" owner:nil options:nil]; return [nibArray firstObject];}结果: 14:13:16.847 XIB注意[] -[ZHDemoView click:]一切正常。总结:从XIB加载出来的是一个对象数组,通常情况下,我们只需要用到一个对象,此时用firstObject或者lastObject皆可。但是当你要使用手势识别器时,别弄错你取出的对象。建议不要在XIB中直接添加手势识别器,通过代码手动创建更稳妥和易于维护。以上就是本文介绍加载带有手势识别器的XIB文件需注意的问题,希望能够帮助到大家。
来源:/n/7169.html
热门搜索:
让图片变得更加清晰 PS图层滤色模式
怎么免费使用漫游聊天记录 怎么设置免费漫游聊天记录
电脑桌面右下角图标如何隐藏
PS效果 使用PS处理相片为正片负冲效果图
电脑自动睡眠怎么取消?有的人在使用计算机的时候将电脑无意机设置成了修眠状态,为了让电脑正常使用怎么取消这种模式呢?
360是一款常见的浏览器,不过有人喜欢就有人不喜欢。有的人不喜欢使用360浏览器可是又不知道该怎么卸载,下面就来教大家360导航怎么卸载。
小米近年来卖得最火的就是红米手机了,低廉的价格,同等价位所不能比的配置等等。红米手机由于低价高配也会存在一定的问题,如果开不了机该怎么办呢?
相信很多人都不明白什么是企业所得税,更不清楚企业所得税的计算方法。其实,企业所得税就是指对取得应税所得、实行独立经济核算的境内企业或者组织,就其生产、经营的纯收益、所得额和其他所得额征收的一种税。 那么,企业所得税计算方法有哪些呢?
清醒时做事,糊涂时读书,大怒时睡觉,无聊时关注图老师为大家准备的精彩内容。下面为大家推荐PS鼠绘衣橱里的怪兽详细教程,无聊中的都看过来。
近来,演员任贤齐自曝电脑被入侵,家产差一点就全被搬光光了,直说自个当下真的不知道该如何是好。究竟电脑被入侵了怎么办呢?图老师电脑网络专栏小编下面给大家详解。
apple pay是什么?近来,ApplePay入华的消息在我国的支付市场上掀起了一阵波澜。昨日(2月18日)上午五点,苹果在我国大陆正式上线ApplePay移动支付服务。不少朋友都会问:apple pay如何使用?apple pay怎么绑定卡?这里我来为大家解答一下吧。
炎夏烈日炎炎,就在你与阳光亲密接触时,也让紫外线有了可乘之机,有的时候,虽然你认真做了防晒的工作,却依旧没能躲过炙热的阳光,晒伤之后,要立马着手修复晒伤的肌肤,那么晒伤后怎么处理呢?下面就一起来看看吧。
脸上肉嘟嘟的女生和男生们是不是选择发型的时候很伤大脑。没关系,我们这里肯定有一款适合你的发型,本文也是大圆脸一枚,下面分享下我收集多年的圆脸女生男生发型以及学会的圆脸发型修饰技巧。
孕妇能吃西瓜吗?面对炎炎夏暑的到来,西瓜作为夏季最常见的水果之一,已经成了人们必吃的解暑水果,作为特殊人群的孕妈妈们也馋的直流口水了,那么问题来了,孕妇到底可以吃西瓜吗?下文为你详解。
如果您有什么好的建议或者疑问,可以联系我们! QQ群: QQ号: 进群、加好友,备注:图老师 小周老师一一为您解答!让我们一起学习、一起进步
< 版权所有 (C) 2016 All Rights Reserved. 湘ICP备号最近开始学习iOS开发,今天上来写第一个iOS笔记
昨天碰到一个需求,在UILable上添加点击事件,网上找了写资料,有人建议用透明的UIButton覆盖,有人建议写一个集成自UILable的类,扩展点击事件的实现。
最后发现没有这么麻烦,只要两步就可以实现。
第一步,将UILable的userInteractionEnabled值设置为YES,这样才能触发点击事件。
第二步,通过TapGestureRecognize注册事件,就算xib操作的连线,UIButton的addTarget,也可以称作为关联、建立联系等等。
代码如下:
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWihTarget:self action:@selector(onClickUILable)];
[myLable addGestureRecognizer:tapGesture];
&代码中myLable为需要添加事件的UILable,onClickUILable为点击UILable后触发事件调用的方法。iphone - UITapGestureRecognizer on a UIButton - Stack Overflow
to customize your list.
Announcing Stack Overflow Documentation
We started with Q&A. Technical documentation is next, and we need your help.
Whether you're a beginner or an experienced developer, you can contribute.
I have a UIButton which has an IBAction as well as a UITapGestureRecognizer to detect double taps.
At the moment it looks like the IBAction is blocking the recognizer. Is there a way to stop this or do
UITapGestureRecognizer even work on buttons? If so wouldn't it be better to just add the recognizers and remove the IBActions?
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget : self action : @selector (handleDoubleTap:)];
[doubleTap setNumberOfTapsRequired:2];
[A1 addGestureRecognizer:doubleTap];
[A2 addGestureRecognizer:doubleTap];
[B1 addGestureRecognizer:doubleTap];
23.9k1079110
11.3k42132243
Looks like you are trying to attach one gesture recognizer to multiple buttons.
A gesture recognizer can only be attached to one view at a time.
So in your case, the last button you are attaching the recognizer to (button B1) probably responds to the double tap but A1 and A2 don't.
Create a separate recognizer for each button.
But all three recognizers can call the same action method (handleDoubleTap:).
However, when you try to do a single tap on a button, there will be a slight delay as it waits to see if it's the beginning of a double tap.
There are ways to reduce the delay but may not be worth it if you can live with the delay and the workarounds bring up other issues.
In your comment, you say you "want to detect if they are pressed at the same time".
To do this, you don't need gesture recognizers.
You can just use the standard control events provided.
First, declare these two methods in your .h file:
-(IBAction)buttonPressed:(UIButton *)
-(IBAction)buttonReleased:(UIButton *)
Use IBAction if you're going to use IB to hook up the events otherwise just use void.
Next, in IB, for each button, hook up the "Touch Down" event with buttonPressed:.
Or, to do it programmatically:
[button1 addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchDown];
[button2 addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchDown];
[button3 addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchDown];
Next, in IB, for each button, hook up the "Touch Up Inside" and "Touch Up Outside" events with buttonReleased:.
Or, to do it programmatically:
[button1 addTarget:self action:@selector(buttonReleased:) forControlEvents:UIControlEventTouchUpInside|UIControlEventTouchUpOutside];
[button2 addTarget:self action:@selector(buttonReleased:) forControlEvents:UIControlEventTouchUpInside|UIControlEventTouchUpOutside];
[button3 addTarget:self action:@selector(buttonReleased:) forControlEvents:UIControlEventTouchUpInside|UIControlEventTouchUpOutside];
Next, add ivars to keep track of how many or which buttons are pressed:
int numberOfButtonsBeingT
NSMutableSet *buttonsBeingT
//alloc+init in viewDidLoad or wherever
@property (assign) int numberOfButtonsBeingT
@property (retain) NSMutableSet *buttonsBeingT
If you just care how many buttons are pressed, you don't need the NSMutableSet.
Finally, add the buttonPressed and buttonReleased methods:
-(IBAction)buttonPressed:(UIButton *)button
numberOfButtonsBeingTouched++;
[buttonsBeingTouched addObject:button];
//your logic here (if numberOfButtonsBeingTouched == 3 ...)
-(IBAction)buttonReleased:(UIButton *)button
numberOfButtonsBeingTouched--;
[buttonsBeingTouched removeObject:button];
//your logic (if any needed) here
60.9k14152156
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you&#39;re looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabled

我要回帖

更多关于 ios xib gesture 的文章

 

随机推荐