您的位置:首页 > 产品设计 > UI/UE

iOS 用UIScrollView不能获取到touchesBegan

2013-08-23 20:58 211 查看
网上查了一下 原来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 都是一样的
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: