代理
用户开始拖拽时,调用scrollViewWillBeginDragging:方法
具体滚动到某个位置时,调用scrollViewDidScroll:方法
用户停止拖拽时,
调用scrollViewDidEndDragging:willDecelerate:方法
#import <UIKit/UIKit.h>
@interface XMGDog : NSObject<UIScrollViewDelegate,UITextFieldDelegate>
@end
#import "XMGDog.h"
@implementation XMGDog
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSLog(@"@监听到了滚动",self);
}
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSLog(@"shouldChangeCharactersInRange--@",string);
return NO;
}
-(void)textFieldDidEndEditing:(UITextField *)textField
{
}
@end
#import "ViewController.h"
#import "XMGDog.h"
@interface ViewController ()<UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
/** dog */
@property(nonatomic,strong)XMGDog * dog ;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"minion"]];
[self.scrollView addSubview:imageView];
self.scrollView.backgroundColor=[UIColor redColor];
self.scrollView.contentSize=imageView.image.size;
self.dog=[[XMGDog alloc]init];
self.scrollView.delegate=self.dog;
UITextField *textField=[[UITextField alloc]init];
textField.frame=CGRectMake(20, 300, 200, 30);
textField.backgroundColor=[UIColor blueColor];
// [textField addTarget:self action:@selector(textChange) forControlEvents:UIControlEventEditingChanged];
textField.delegate=self.dog;
[self.view addSubview:textField];
}
//-(void)textChange:(UITextField*)textField
//{
// NSLog(@"tEXTchang--------@",textField.text);
//}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark-<UIScrollViewDelegate>
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
//滚动时
}
-(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
//开始
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
//结束
}
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
//减速完毕
}
@end