iOS 用UIScrollView不能获取到touchesBegan

iOS 用UIScrollView不能获取到touchesBegan网上查了一下 原来UIScrollView是没有继承touchesBegan方法的所以要自己重写UIScrollView然后继承 touchesBegan等方法才可以用重写UIScrollView很简单代码下.h//// myScrollView.h// WFClient//// Createdby屎壳郎情调on1

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

网上查了一下 原来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.net/164174.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号