大家好,又见面了,我是你们的朋友全栈君。
网上查了一下 原来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