给多个label添加tapios tap cell手势冲突和识别点击的是哪个label的问题

> C# 动态生成的多个label 点击后能跳转到另一个窗口并且能知道是哪个label事件解决思路
C# 动态生成的多个label 点击后能跳转到另一个窗口并且能知道是哪个label事件解决思路
nsaboy & &
发布时间: & &
浏览:167 & &
回复:13 & &
悬赏:0.0希赛币
C# 动态生成的多个label 点击后能跳转到另一个窗口并且能知道是哪个label事件C# 动态生成的多个label 点击后能跳转到另一个窗口并且能知道是哪个label触发的事件& 先感谢大家了最佳答案给高分
label是没有点击响应的,为什么不用Button呢?动态生成button不是一样么?自己看设计器里面的代码,照猫画虎就可以了。
nsdlfj & &
& & (0)(0)如果我没有搞错的话,label是不能点击的如果要点击的话,应该是button. 在designer里面点击你的button一般会自动生成类似的代码:  C# code  private void button1_Click(object sender, EventArgs e)
nsdngu & &
& & (0)(0)如果要换行
那你就继承一个BUTTON 或者继承一个 LABEL
然后添加 事件
& & (0)(0)对,重写一个BUTTON
nsfself & &
& & (0)(0)重写一个CONTROL也行啊,里面设置一个成员变量INDEX,在动态生成的时候把各个CONTROL设上不同的INDEX。这样在回调函数当中就可以通过INDEX得到到底是哪个被点击了。
nscyyy & &
& & (0)(0)rewrite
NSChenBiao & &
& & (1)(0)不管是什么控件,都可以挂到private void button1_Click(object sender, EventArgs e)上吧,这个函数中看一下sender是谁不就知道谁发的了,呵呵~~~
nsfzxiao & &
& & (0)(0)只要能获取到label的属性,就可以传递
& & (0)(0)谁跟你们说LABEL 没有点击的?
nsdragon100 & &
& & (0)(0)
nsfzxiao & &
& & (0)(0)从上看到下. 问题需求我不太清楚, 估计是我笨了.
只是有一个问题: LABEL没有CLICK事件  
真的没有吗 
传值很简单. 什么都可以传. 方法对了就行.
NSChenBiao & &
& & (0)(0)建立一个System.Windows.Forms.Label的继承类
nscyyy & &
& & (0)(0)我以前做过这方面的东西,就是类似答题卡上的一道题的ABCD选项我当时是做了一个复合控件,你只要为复合控件定义一个属性记录控件ID就OK了如果不做复合控件,可以对Lable类进行重构nsdngu & &
& & (0)(0)
本问题标题:
本问题地址:
温馨提示:本问题已经关闭,不能解答。
暂无合适的专家
&&&&&&&&&&&&&&&
希赛网 版权所有 & &&UIGestureRecognizer-iOS手势识别浅析
收拾识别的重要性就不用我在赘述了。
iOS支持多种手势:Swipe,Tap,Rotation,Pinch,Pan,Long press。
手势识别应有的一般步骤为:
1.创建一个合适的手势识别器的对象。&
2.把这个手势识别器的对象绑定到一个视图上。&
3.添加一些捕获手势事件发生的方法。
一、滑动手势的基本应用-UISwipeGestureRecognizer
(void)viewDidLoad
viewDidLoad];
& self.view.backgroundColor = [UIColor whiteColor];
& // 初始化滑动手势识别器
& self.swipeGestureRecognizer = [[UISwipeGestureRecognizer alloc]
initWithTarget:self
& & action:@selector(handleSwipes:)];
定义滑动方向,即:向X滑动
& self.swipeGestureRecognizer.direction =
UISwipeGestureRecognizerDirectionLeft;
& // 几个手指
& self.swipeGestureRecognizer.numberOfTouchesRequired = 1;
& // 将手势添加到某个UI上
[self.view
addGestureRecognizer:self.swipeGestureRecognizer];
手势处理事件
handleSwipes:(UISwipeGestureRecognizer *)paramSender{
(paramSender.direction &
UISwipeGestureRecognizerDirectionDown){
& & NSLog(@"Swiped Down.");
(paramSender.direction &
UISwipeGestureRecognizerDirectionLeft){
& & NSLog(@"Swiped Left.");
(paramSender.direction &
UISwipeGestureRecognizerDirectionRight){
& & NSLog(@"Swiped Right.");
(paramSender.direction &
UISwipeGestureRecognizerDirectionUp){
& & NSLog(@"Swiped Up.");
二、旋转手势的基本应用-UIRotationGestureRecognizer
UIRotationGestureRecognizer主要是处理旋转手势的类。
使用原理都是一样的。
贴个代码:
(void)viewDidLoad
viewDidLoad];
& self.view.backgroundColor = [UIColor whiteColor];
& self.helloWorldLabel = [[UILabel alloc] initWithFrame:CGRectZero];
& self.helloWorldLabel.text
= @"Hello, World!";
& self.helloWorldLabel.font
= [UIFont systemFontOfSize:16.0f];
[self.helloWorldLabel sizeToFit];
& self.helloWorldLabel.center = self.view.center;
[self.view
addSubview:self.helloWorldLabel];
& self.rotationGestureRecognizer = [[UIRotationGestureRecognizer
alloc] initWithTarget:self
& & action:@selector(handleRotations:)];
[self.view
addGestureRecognizer:self.rotationGestureRecognizer];
旋转手势处理事件
handleRotations:(UIRotationGestureRecognizer
*)paramSender{
(self.helloWorldLabel == nil){
设置标签的旋转值。这个值用弧度来表示。即:2*PI
& self.helloWorldLabel.transform = CGAffineTransformMakeRotation(self.rotationAngleInRadians +paramSender.rotation);
(paramSender.state ==
UIGestureRecognizerStateEnded){
& self.rotationAngleInRadians +=
paramSender.rotation;
1.当我们声明一个旋转手势类,并且将它添加到View上的时候
&self.rotationGestureRecognizer&=
[[UIRotationGestureRecognizer&alloc]&initWithTarget:self
& &action:@selector(handleRotations:)];
&&[self.view&addGestureRecognizer:self.rotationGestureRecognizer];
UIRotationGestureRecognizer类的实例将监听View的旋转事件。并执行handleRotations方法。
在旋转过程中,会一直执行handleRotations方法。并监听旋转的状态等数据。
这个旋转手势识别器将会给我们传递一组旋转的角度,旋转手势识别器一直还在进行一
个监听的动作,因此他会一边监听我们手势旋转的角度,一边把这些捕获到的角度传递给我
们,然后我们可以利用这些角度信息,进行一些位置的计算,然后调整下一个显示的位置。&
旋转方法:
handleRotations:(UIRotationGestureRecognizer&*)paramSender
中包括了很多关于旋转的信息。
typedef NS_ENUM(NSInteger,
UIGestureRecognizerState) {
UIGestureRecognizerStatePossible, &
UIGestureRecognizerStateBegan,& &
UIGestureRecognizerStateChanged,&&
UIGestureRecognizerStateEnded,&
UIGestureRecognizerStateCancelled,&&
UIGestureRecognizerStateFailed,
UIGestureRecognizerStateRecognized = UIGestureRecognizerStateEnded&
paramSender.rotation
三、拖拽手势的基本应用-UIPanGestureRecognizer
UIPanGestureRecognizer类可以实现在应用中添加利用手指来达到图层拖拉的应用。
这个手势识别器类,就像他的名字一样,可以捕获监测拖动的手势。&
拖动的手势一般都是用手指来操作产生的,一般当拖动手势产生的时候会顺序的经过如
下几个阶段。
(void)viewDidLoad
viewDidLoad];
& self.view.backgroundColor = [UIColor whiteColor];
& & CGRect labelFrame = CGRectMake(0.0f,0.0f, 150.0f, 100.0f);
& & self.helloWorldLabel = [[UILabel alloc] initWithFrame:labelFrame];
& self.helloWorldLabel.text
= @"Hello World";
& self.helloWorldLabel.backgroundColor = [UIColor blackColor];
& self.helloWorldLabel.textColor =
[UIColor whiteColor];
& self.helloWorldLabel.textAlignment = UITextAlignmentCenter;
& self.helloWorldLabel.userInteractionEnabled = YES;//
设置可以设置用户操作
& & [self.view addSubview:self.helloWorldLabel];
& & self.panGestureRecognizer =
[[UIPanGestureRecognizer alloc] initWithTarget:self
action:@selector(handlePanGestures:)];
& & self.panGestureRecognizer.minimumNumberOfTouches
& & self.panGestureRecognizer.maximumNumberOfTouches
Label加入拖拽手势识别器,这样,Label就会相应推拽操作
& & [self.helloWorldLabel
addGestureRecognizer:self.panGestureRecognizer];
拖拽手势处理事件
handlePanGestures:(UIPanGestureRecognizer*)paramSender{
& & if (paramSender.state != UIGestureRecognizerStateEnded
&& paramSender.state !=
UIGestureRecognizerStateFailed){
获取手指在屏幕中的坐标
& CGPoint location = [paramSender
locationInView:paramSender.view.superview];
& paramSender.view.center =//
重新设置视图的位置
locationInView
函数放回一个CGPint类型的值,表示触摸在view这个试图上的位置,这里放回的位置是针对view的坐标系的。
调用时,如果传入view为nil的时候,返回的CGPoint是触摸点在整个窗口中的位置。
四、长按手势的基本应用-UILongPressGestureRecognizer
原理一样,直接贴代码,啥都懂了!!!
(void)viewDidLoad
viewDidLoad];
& self.view.backgroundColor = [UIColor whiteColor];
& self.dummyButton =
buttonWithType:UIButtonTypeRoundedRect];
& self.dummyButton.frame
= CGRectMake(0.0f,0.0f,
72.0f, 37.0f);
& self.dummyButton.center = self.view.center;
& & [self.view addSubview:self.dummyButton];
& self.longPressGestureRecognizer = [[UILongPressGestureRecognizer
alloc] initWithTarget:self
action:@selector(handleLongPressGestures:)];
& // 要求的手指数量
& self.longPressGestureRecognizer.numberOfTouchesRequired = 2;
& // 对大的移动距离,当手指按住并且移动超过100px后,UILongPressGestureRecognizer
将不会再识别
& self.longPressGestureRecognizer.allowableMovement = 100.0f;
& // 需要的最少事件(秒),即:至少长按1秒,UILongPressGestureRecognizer
& self.longPressGestureRecognizer.minimumPressDuration = 1.0;
[self.view
addGestureRecognizer:self.longPressGestureRecognizer];
拖拽手势处理事件
handleLongPressGestures:(UILongPressGestureRecognizer
*)paramSender{
([paramSender isEqual:self.longPressGestureRecognizer]){
(paramSender.numberOfTouchesRequired == 2){
第<span STYLE="color: #个手指的触摸点
CGPoint touchPoint1 =
[paramSender locationOfTouch:0 inView:paramSender.view];
第<span STYLE="color: #个手指的触摸点
CGPoint touchPoint2 =
[paramSender locationOfTouch:1 inView:paramSender.view];
计算中心点坐标
CGFloat midPointX =
(touchPoint1.x +
touchPoint2.x) / 2.0f;
CGFloat midPointY =
(touchPoint1.y +
touchPoint2.y) / 2.0f;
CGPoint midPoint = CGPointMake(midPointX, midPointY);
self.dummyButton.center = midP
& } else {
五、点击手势的基本应用-UITapGestureRecognizer
(void)viewDidLoad
viewDidLoad];
& self.view.backgroundColor = [UIColor whiteColor];
& self.tapGestureRecognizer = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleTaps:)];
& // 手指数
& self.tapGestureRecognizer.numberOfTouchesRequired = 2;
& // 连续点击次数
& self.tapGestureRecognizer.numberOfTapsRequired = 3;
& // 添加手势识别
[self.view
addGestureRecognizer:self.tapGestureRecognizer];
点击处理事件
(void) handleTaps:(UITapGestureRecognizer*)paramSender{
& & NSUInteger touchCounter = 0;
& & for (touchCounter = 0;touchCounter &
paramSender.numberOfTouchesRequired;touchCounter++){
& & // 循环获得每个手指在view中的坐标点
touchPoint =[paramSender locationOfTouch:touchCounter inView:paramSender.view];
& NSLog(@"Touch
#%lu: %@",(unsigned
long)touchCounter+1, NSStringFromCGPoint(touchPoint));
六、放大和缩小手势的基本应用-UIPinchGestureRecognizer
(void)viewDidLoad
viewDidLoad];
& self.view.backgroundColor = [UIColor whiteColor];
& & CGRect labelRect = CGRectMake(0.0f,0.0f,200.0f,200.0f);
& & self.myBlackLabel = [[UILabel alloc] initWithFrame:labelRect];
& self.myBlackLabel.center = self.view.center;
& self.myBlackLabel.backgroundColor = [UIColor blackColor];
& self.myBlackLabel.userInteractionEnabled = YES;
[self.view
addSubview:self.myBlackLabel];
& self.pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc]
initWithTarget:self
& & action:@selector(handlePinches:)];
[self.myBlackLabel addGestureRecognizer:self.pinchGestureRecognizer];
放大缩小处理事件
手势状态监听方法会一直执行:执行状态有:
// UIGestureRecognizerStateBegan
// UIGestureRecognizerStateChanged
// UIGestureRecognizerStateEnded
handlePinches:(UIPinchGestureRecognizer*)paramSender{
(paramSender.state ==
UIGestureRecognizerStateEnded){
& self.currentScale = paramSender.scale;
& & } else if
(paramSender.state ==
UIGestureRecognizerStateBegan
&& self.currentScale != 0.0f){
& paramSender.scale = self.currentScale;
& & if (paramSender.scale != NAN &&
paramSender.scale !=
& paramSender.view.transform = CGAffineTransformMakeScale(paramSender.scale,paramSender.scale);
就不解释了,原理是惊人的相似啊!因为都是这几个方法都是兄弟姐妹!都是一个妈生的!
UIGestureRecognizer!!!!
希望对你有所帮助!
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
您的访问请求被拒绝 403 Forbidden - ITeye技术社区
您的访问请求被拒绝
亲爱的会员,您的IP地址所在网段被ITeye拒绝服务,这可能是以下两种情况导致:
一、您所在的网段内有网络爬虫大量抓取ITeye网页,为保证其他人流畅的访问ITeye,该网段被ITeye拒绝
二、您通过某个代理服务器访问ITeye网站,该代理服务器被网络爬虫利用,大量抓取ITeye网页
请您点击按钮解除封锁&&&&&WPAttributedMarkup能给Label中某关键字添加文字效果或点击事件。Label中的某个关键字词可以改变字体的特性如颜色、加粗,下划线等,也可以为某个关键字词添加点击事件。
测试环境:
&&[Code4App]编译测试
相关代码:
(2424次查看,332次下载) WeatherFontIcon提供多个天气状况的图标,适用于天气类App,可以变换颜色,大小。图标的使用跟UILabel一样简单方便。
(2792次查看,306次下载) JBCountdownLabel是UILabel的一个扩展,实现倒数功能。可以设置倒数时间。可以通过委托方法执行倒数结束后的操作。
(5706次查看,1200次下载) MZSelectableLabel是一个带有选择功能的标签。通过颜色检测,可以把指定颜色的标签内容转化为链接。Demo实现了点击链接和长按链接效果。
(3799次查看,617次下载) 实现具有渐变背景颜色的Label。
(3673次查看,828次下载) 实现相应点击UILabel中的任意一个字母。
(12319次查看,3365次下载) 继承系统UIlabel,改写了字间距、行间距、段间距等,可以进行动态修改。可以动态获得Label的高度。支持自使用定义字体。
小编注:感谢开发者@lxh_302 发布代码于。
(6851次查看,3684次下载) 实现逐个渐隐渐现的文字效果,类似Secret app。
(11344次查看,2254次下载) 给 UILabel 加上删除线(中划线)。
小编注:感谢开发者@盼叔叔 发布代码于。
代码评论:
登录后方可评论
求指导怎么判断点击的是那个字
登录后方可评论
中文不可点击,怎么办
登录后方可评论
ios 9.0 上面点击某些标签没反应,不进点击事件,好像是第一行可以,第二行以后就不行了,求作者解决,急急急急。
登录后方可评论
求联系作者
登录后方可评论
字体小于16不能用
登录后方可评论
有点问题,文字和标签多的时候,点击不够准备,点击的逻辑可能没减去标签的长度
登录后方可评论
登录后方可评论
不能打开查看?
登录后方可评论
-控件分类-
-功能分类-}

我要回帖

更多关于 给label添加手势 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信