学习笔记-斯坦福iOS7-第十课:多线程,滚动视图

1.Multithreading
a.得到主队列

dispatch_queue_t main = dispatch_get_main_queue();   

or

NSOperationQueue *main = [NSOperationQueue mainQueue];


b.创建一个队列(非主队列)

dispatch_queue_t other = dispatch_queue_create("name", NULL);


c.切换到主线程
- (void)performSelectorOnMainThread:(SEL)aMethod
withObject:(id)obj

    waitUntilDone:(BOOL)waitUntilDone;   

or

dipatch_async(dispatch_get_main_queue(), ^{ });


2. UIScrollView
a. 创建
scrollView.frame = CGRectMake(0,0,300,400);
scrollView.contentSize = CGSizeMake(500,1000);
subView.frame = CGRectMake(0,0,500,1000);
[scrollView addSubview:subView];
[self.view addSubview:scrollView];

b. 当前显示区域
CGPoint point = scrollView.contentOffset;
CGRect visibleRect = [scrollView convertRect:scrollView.bounds toView:subView];

c. 滚动到某个区域
- (void)scrollRectToVisible:(CGRect)aRect animated:(BOOL)animated;

d. 缩放
minimumZoomScale ,maxmumZoomScale 最小最大缩放比例
需实现委托: - (UIView*)viewForZoomingInScrollView:(UIScrollView*)sender;
返回需要缩放的视图;否则缩放无效的。

代码实现:
- (void)setZoomScale:(float)scale animated:(BOOL)animated;
- (void)zoomToRect:(CGRect)zoomRect animated:(BOOL)animated;

e. 各种委托,自己看文档


3. demo
a. 创建ImageViewController,实现imageUrl属性,调用者传url,内部读取到这个url,下载图片,加载显示;
b. 点击不同按钮,调用ImageViewController,传不同url,功能实现,但是卡,并且图片显示不全;
c. 添加ScrollView,实现缩放,可以显示任何大小图片;
d. 实现多线程下载图片,解决卡的问题;

e. 添加activityIndicator控件,提高用户体验;



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值