下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。
内存溢出小编现在分享给大家,也给大家做个参考。
/////记得添加 代理 <uiscrollviewdelegate> UIScrollVIEw* sv = [[UIScrollVIEw alloc] initWithFrame:CGRectMake(0,320,460)]; [self.vIEw addSubvIEw:sv]; [sv release]; //常用属性 //真正大小,在这里frame仅代表可视位置和范围 sv.contentSize = CGSizeMake(320 * 17,460 * 2); //偏移量,frame左上角顶点相对于contentVIEw左上角顶点的偏移量 sv.contentOffset = CGPointMake(0,0); //[sv setContentOffset: animated:] //分页 sv.pagingEnabled = YES; //设置额外的空间 sv.contentInset = UIEdgeInsetsMake(0,0); //锁定方向,左右滑动和上下滑动不能同时进行 sv.directionalLockEnabled = YES; //反d效果 sv.bounces = YES; //水平方向上保持反d效果 sv.alwaysBounceHorizontal = YES; //垂直方向上保持反d效果 sv.alwaysBounceVertical = YES; //开启滑动 sv.scrollEnabled = YES; //隐藏水平状态条 sv.showsHorizontalScrollindicator = YES; //隐藏垂直状态条 sv.showsverticalScrollindicator = YES; //状态条位置 //sv.scrollindicatorInsets = UIEdgeInsetsMake(100,100,100); //状态条类型 sv.indicatorStyle = UIScrollVIEwIndicatorStyleDefault; //减速速率 范围0~1 sv.decelerationRate = 0.5; //delaysContenttouches //sv.delaysContenttouches = NO; sv.delegate = self; sv.tag = 10; //添加内容 图片 for (int i = 0; i < 17; i++) { UIScrollVIEw* subSv = [[UIScrollVIEw alloc] initWithFrame:CGRectMake(i * 320,460)]; subSv.delegate = self; subSv.minimumZoomScale = 0.5; subSv.maximumZoomScale = 2.0; [sv addSubvIEw:subSv]; [subSv release]; UIImageVIEw* imageVIEw = [[UIImageVIEw alloc] initWithFrame:CGRectMake(0,460)]; imageVIEw.image = [UIImage imagenamed:[Nsstring stringWithFormat:@"10_%d.jpg",i]]; [subSv addSubvIEw:imageVIEw]; [imageVIEw release]; } //这个button 只显示在第一张图片上 UIbutton* button = [UIbutton buttonWithType:UIbuttonTypeRoundedRect]; button.frame = CGRectMake(100,40); button.backgroundcolor = [UIcolor yellowcolor]; [sv addSubvIEw:button]; [button addTarget:self action:@selector(buttonClick) forControlEvents:UIControlEventtouchUpInsIDe]; ///事件 - (voID)buttonClick{ NSLog(@"点击了");// UIScrollVIEw* sv = (UIScrollVIEw*)[self.vIEw vIEwWithTag:10];// [sv setContentOffset:CGPointMake(320 * 5,0) animated:YES]; self.vIEw.hIDden=YES;} //缩放- (UIVIEw *)vIEwForZoomingInScrollVIEw:(UIScrollVIEw *)scrollVIEw{ if (scrollVIEw.tag == 10) { return nil; } for (UIVIEw* vIEw in scrollVIEw.subvIEws) { if ([vIEw isKindOfClass:[UIImageVIEw class]]) { return vIEw; } } return nil;} //滑动调用,contentOffSet发生偏移- (voID)scrollVIEwDIDScroll:(UIScrollVIEw *)scrollVIEw{ //int page = scrollVIEw.contentOffset.x / 320; //NSLog(@"%d",page); } //将要开始拖拽- (voID)scrollVIEwWillBeginDragging:(UIScrollVIEw *)scrollVIEw{ NSLog(@"将要开始拖拽");} //将要结束拖拽- (voID)scrollVIEwWillEndDragging:(UIScrollVIEw *)scrollVIEw withVeLocity:(CGPoint)veLocity targetContentOffset:(inout CGPoint *)targetContentOffset{ NSLog(@"将要结束拖拽");} //结束拖拽- (voID)scrollVIEwDIDEndDragging:(UIScrollVIEw *)scrollVIEw willDecelerate:(BOol)decelerate{ NSLog(@"结束拖拽 %d",decelerate);} //将要开始减速- (voID)scrollVIEwWillBeginDecelerating:(UIScrollVIEw *)scrollVIEw{ NSLog(@"将要开始减速");} //结束减速- (voID)scrollVIEwDIDEndDecelerating:(UIScrollVIEw *)scrollVIEw{ NSLog(@"结束减速");} - (voID)scrollVIEwDIDEndScrollingAnimation:(UIScrollVIEw *)scrollVIEw{ NSLog(@"结束动画");} - (BOol)scrollVIEwShouldScrollTotop:(UIScrollVIEw *)scrollVIEw{ NSLog(@"要滑动到顶部"); return YES;} - (voID)scrollVIEwDIDScrollTotop:(UIScrollVIEw *)scrollVIEw{ NSLog(@"已经滑动到顶部");} //将要开始缩放- (voID)scrollVIEwWillBeginZooming:(UIScrollVIEw *)scrollVIEw withVIEw:(UIVIEw *)vIEw{ NSLog(@"开始缩放");} //正在缩放- (voID)scrollVIEwDIDZoom:(UIScrollVIEw *)scrollVIEw{ NSLog(@"缩放中");} //结束缩放- (voID)scrollVIEwDIDEndZooming:(UIScrollVIEw *)scrollVIEw withVIEw:(UIVIEw *)vIEw atScale:(float)scale{ NSLog(@"缩放结束:%f",scrollVIEw.zoomScale);}
以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
总结以上是内存溢出为你收集整理的UIScrollView 滚动视图全部内容,希望文章能够帮你解决UIScrollView 滚动视图所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)