15.11.25学习笔记 炫酷的滚动视图
来源:互联网 发布:92kaifa 域名秀 编辑:程序博客网 时间:2024/06/05 17:12
描述:滚动视图上的图片渐变 其他控件随着滚动
作者的实现方法:
工具xcode7.1
//类名 实现滚动视图 图片不随滚动视图滚动 描述文字滚动
1.新建工程用pod导入 pod 'LGSublimationView', '~> 1.0.0'
2.引入类名和代理#import <LGSublimationViewLGSublimationView.h>
<LGSublimationViewDelegate>
主体代码
-(void)loadView
{
[super loadView];
LGSublimationView *lgSublimer = [[LGSublimationViewalloc]initWithFrame:self.view.bounds];
//加载图片
NSMutableArray*views = [NSMutableArraynew];
for (int i =1; i<=4; i++) {
UIImageView *view = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0, self.view.frame.size.width,self.view.frame.size.height)];
view.image = [UIImageimageNamed:[NSStringstringWithFormat:@"%i.jpg",i]];
view.contentMode =UIViewContentModeScaleAspectFill;
[views addObject:view];
}
//设置标题的字体属性
lgSublimer.titleLabelTextColor = [UIColorwhiteColor];
lgSublimer.descriptionLabelTextColor = [UIColorwhiteColor];
lgSublimer.delegate = self;
lgSublimer.titleLabelFont = [UIFontfontWithName:@"HelveticaNeue-Light"size:20];
lgSublimer.descriptionLabelFont = [UIFontfontWithName:@"HelveticaNeue-UltraLight"size:20];
lgSublimer.titleStrings =@[@"This is title one",
@"This is title two",
@"This is title three",
@"This is title four"];
//设置描述的字体
lgSublimer.descriptionStrings =@[@"This is a description of one",
@"This is description two and also happens to be multi line, which is sweet"
,@"This is description three",
@"follow luke on twitter @lukejgeiger"];
//图片加到视图上
lgSublimer.viewsToSublime = views;
//设置视图的背景色
UIView* shadeView = [[UIViewalloc]initWithFrame:lgSublimer.frame];
shadeView.backgroundColor = [UIColorblackColor];
shadeView.alpha = .5;
lgSublimer.inbetweenView = shadeView;
[self.viewaddSubview:lgSublimer];
}
-(void)lgSublimationView:(LGSublimationView *)view didEndScrollingOnPage:(NSUInteger)page
{
NSLog(@"Current Page %i",(int)page);
}
我的模拟方法
具体思路就是 通过滚动视图的偏移量控制图片的透明度
#import "ViewController.h"
@interface ViewController ()<UIScrollViewDelegate>
@property (nonatomic,strong)UIScrollView *scrollview;
@property UIImageView *imageview;
@property UIImageView *imageview2;
@property UIImageView *imageview3;
@property UIImageView *imageview4;
@end
//仿写的思路 背景叠加4张图片 上面覆盖透明的滚动视图 视图上加对应的4个标题通过滚动视图的偏移量控制图片的显示与否
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
_imageview4=[[UIImageViewalloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height)];
_imageview4.contentMode=UIViewContentModeScaleAspectFill;
_imageview4.image=[UIImageimageNamed:[NSStringstringWithFormat:@"%d.jpg",4]];
[self.viewaddSubview:_imageview4];
_imageview3=[[UIImageViewalloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height)];
_imageview3.contentMode=UIViewContentModeScaleAspectFill;
_imageview3.image=[UIImageimageNamed:[NSStringstringWithFormat:@"%d.jpg",3]];
[self.viewaddSubview:_imageview3];
_imageview2=[[UIImageViewalloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height)];
_imageview2.contentMode=UIViewContentModeScaleAspectFill;
_imageview2.image=[UIImageimageNamed:[NSStringstringWithFormat:@"%d.jpg",2]];
[self.viewaddSubview:_imageview2];
_imageview=[[UIImageViewalloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height)];
_imageview.contentMode=UIViewContentModeScaleAspectFill;
_imageview.image=[UIImageimageNamed:[NSStringstringWithFormat:@"%d.jpg",1]];
[self.viewaddSubview:_imageview];
//加4个label
_scrollview=[[UIScrollViewalloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height)];
self.scrollview.delegate=self;
self.scrollview.showsHorizontalScrollIndicator=YES;
self.scrollview.pagingEnabled=YES;
self.scrollview.scrollEnabled=YES;
self.scrollview.contentSize=CGSizeMake(4*self.view.frame.size.width,0);
self.scrollview.backgroundColor=[UIColorclearColor];
//创建4个lable
for (int i=0;i<4;i++) {
UILabel *label=[[UILabelalloc]initWithFrame:CGRectMake(100+i*self.view.frame.size.width,300,200,50)];
label.text=[NSStringstringWithFormat:@"第%d个页面",i+1];
[_scrollview addSubview:label];
}
[self.viewaddSubview:_scrollview];
// Do any additional setup after loading the view, typically from a nib.
}
//在代理
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
//计算偏移量
if ((scrollView.contentOffset.x/self.view.frame.size.width>0)&&(scrollView.contentOffset.x/self.view.frame.size.width<1)) {
self.imageview.alpha=1-scrollView.contentOffset.x/self.view.frame.size.width;
}
if ((scrollView.contentOffset.x/self.view.frame.size.width>1)&&(scrollView.contentOffset.x/self.view.frame.size.width<2)) {
self.imageview2.alpha=2-scrollView.contentOffset.x/self.view.frame.size.width;
}
if ((scrollView.contentOffset.x/self.view.frame.size.width>2)&&(scrollView.contentOffset.x/self.view.frame.size.width<3)) {
self.imageview3.alpha=3-scrollView.contentOffset.x/self.view.frame.size.width;
}
if ((scrollView.contentOffset.x/self.view.frame.size.width>3)&&(scrollView.contentOffset.x/self.view.frame.size.width<4)) {
self.imageview4.alpha=4-scrollView.contentOffset.x/self.view.frame.size.width;
}
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
- 15.11.25学习笔记 炫酷的滚动视图
- 炫酷的滚动视图
- android学习笔记28:滚动视图
- Android学习笔记(2)--滚动视图
- iOS学习笔记--滚动视图(UIScrollView)
- Android学习笔记(31):滚动视图ScrollView
- Android学习笔记技巧之垂直和水平滚动视图
- iOS学习笔记——滚动视图(scrollView)
- iOS学习笔记——滚动视图(scrollView)
- iOS学习笔记——滚动视图(scrollView)
- Android学习笔记-使用Scroller来滚动视图
- 学习笔记-斯坦福iOS7-第十课:多线程,滚动视图
- MYSQL视图的学习笔记
- UI笔记_UIScrollView滚动视图
- 滚动视图的调整
- iOS 之滚动视图的定时滚动
- 滚动视图UIScrollView设置滚动的方法
- 滚动视图的自动循环滚动
- vlfeat-0.9.16 做kmeans聚类时遇到的bug
- Android网络编程六:(2)Universal-Image-Loader之缓存策略
- XMPP
- 深入理解Hibernate的三种状态
- Android 超高仿微信图片选择器 图片该这么加载
- 15.11.25学习笔记 炫酷的滚动视图
- 11087 统计逆序对
- WebViewJavascriptBridge 原理分析
- java 集合 HashMap
- imageBeffer绘制图形
- 程序员不可不知的英文词汇(4)
- 匿名内部类
- 知名App第三方库汇总2014.10
- 创建及使用静态库(.a)的步骤整理