当前位置:编程学习 > 网站相关 >>

UIScrollView代理方法的实现

1.开始滑动
 
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
 
{
 
    NSLog(@"scrollViewWillBeginDragging");
 
}
 
2.将要结束滑动
 
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inoutCGPoint *)targetContentOffset NS_AVAILABLE_IOS(5_0)
 
{
 
    NSLog(@"scrollViewWillEndDragging");
 
}
 
注意该方法常用在当用户滚动完屏幕时加载图片,HTTP请求加载,这样会提高效率
 
3.已经结束滑动
 
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
 
{
 
    NSLog(@"scrollViewDidEndDragging");
 
}
 
4.将要减速
 
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
 
{
 
    NSLog(@"scrollViewWillBeginDecelerating");
 
}
 
5.已经减速
 
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView   // called when scroll view grinds to a halt
 
{
 
    NSLog(@"scrollViewDidEndDecelerating");
 
}
 
6.已经停止滚动
 
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
 
{
 
    NSLog(@"scrollViewDidEndScrollingAnimation");
 
}
 
isMemberOfClass和isKindOfClass的异同
 
两者都能检测出一个对象是否是某个类的成员,区别是:
 
isKindOfClass不但可以检测出一个对象是否是某一类的成员,也可以确定一个对象是否是派生自该类的成员,而isMemberOfClass不行
 
7.用代理方法实现图片的放大缩小
 
 
 
-(void)viewDidLoad  
{  
    ScrollView=[[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)] autorelease];  
    ScrollView.delegate=self;  
    ScrollView.backgroundColor=[UIColor redColor];  
    ScrollView.scrollsToTop=YES;  
    ScrollView.contentSize=CGSizeMake(320, 460);  
    ScrollView.maximumZoomScale=2;  
    ScrollView.minimumZoomScale=0.5;  
    ScrollView.backgroundColor=[UIColor yellowColor];  
    [self.view addSubview:ScrollView];  
      
  imageView=[[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)] autorelease];  
    imageView.image=[UIImage imageNamed:@"image1.jpg"];  
    [ScrollView addSubview:imageView];  
   
}  
  
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView  
{  
    return imageView;  
}  
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view NS_AVAILABLE_IOS(3_2)  
{  
    NSLog(@"begin scrollview");  
}  
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale  
{  
NSLog(@"did  end  finih");  
}  

 

 
补充:综合编程 , 其他综合 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,