前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >iOS 用UIScrollView不能获取到touchesBegan

iOS 用UIScrollView不能获取到touchesBegan

作者头像
全栈程序员站长
发布2022-09-15 10:20:26
4110
发布2022-09-15 10:20:26
举报
文章被收录于专栏:全栈程序员必看

大家好,又见面了,我是你们的朋友全栈君。

网上查了一下 原来UIScrollView是没有继承touchesBegan方法的 所以要自己重写UIScrollView 然后继承

touchesBegan 等方法才可以用

重写

UIScrollView很简单

代码下

.h

//

// myScrollView.h

// WFClient

//

// Created by 屎壳郎情调 on 13-8-23.

// Copyright (c) 2013年 ibokan. All rights reserved.

//

#import <UIKit/UIKit.h>

@interface myScrollView : UIScrollView

@end

.m

//

// myScrollView.m

// WFClient

//

// Created by 屎壳郎情调 on 13-8-23.

// Copyright (c) 2013年 ibokan. All rights reserved.

//

#import “myScrollView.h”

@implementation myScrollView

– (id)initWithFrame:(CGRect)frame

{

self = [super initWithFrame:frame];

if (self) {

// Initialization code

}

return self;

}

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

[super touchesBegan:touches withEvent:event];

//做你想要的操作

}

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{

[super touchesEnded:touches withEvent:event];

//做你想要的操作

}

/*

// Only override drawRect: if you perform custom drawing.

// An empty implementation adversely affects performance during animation.

– (void)drawRect:(CGRect)rect

{

// Drawing code

}

*/

@end

使用的时候很简单 直接

//滚动视图

myScrollView *scrollView= [[myScrollView alloc] initWithFrame: CGRectMake( 0, 0, 320, 460)];

用法和UIScrollView 都是一样的

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/164174.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档