圖片輪播器 部分自用

圖片輪播器中用到了UIScrollView  和 他的代理

圖片的縮放
1. 使用代理方法
viewForZoomingInScrollView:(UIScrollView *)scrollView
告訴scrollView 要對哪個view進行縮放

2. 必須設置最大的放大倍數, 最小的縮小倍數
// 最大放大到3
_scrollView.maximumZoomScale =
3;

// 最小 縮小到 0.2
_scrollView.minimumZoomScale =
0.2;


. 圖片輪播器

// 分頁效果
scrollView.pagingEnabled  =
YES;

UIPageControle
// 共有多少個點
numberOfPages

// 當前點
// 取值範圍 0 -- (numberOfPages - 1)
currentPage

// 設置當前點的顏色
// Indicator : 指示器
currentPageIndicatorTintColor


// 設置非當前點的顏色
pageIndicatorTintColor

計時器:
// 會自動開始執行
/**
 TimeInterval :
時間間隔
 target :
一般是控制器 self
 selector :
要執行的方法
 userInfo :
自定義的參數
 repeats :
是否重複
 
 
每隔一秒鐘的時間, 去調用  target(控制器) didClickButton: 參數爲nil,
 */

_timer = [NSTimer scheduledTimerWithTimeInterval:
10
                                          target:
self
                                        selector:
@selector(didClickButton:)
                                        userInfo:
nil
                                         repeats:
YES];

fire  :
立即執行, 不會等待  timerInterval 之後再去執行

invalidate :
計時器 無效, 一旦無效化之後, 就必須重新實例化 timer

如果使用這種方式去實例化timer
_timer = [NSTimer timerWithTimeInterval:
1
                                 target:
self
                               selector:
@selector(didClickButton:)
                               userInfo:
nil
                                repeats:
YES];

必須得手動的把timer 放置到 runLoop當中
NSRunLoop *mainLoop = [NSRunLoop currentRunLoop];
// timer 添加到runLoop
/**
 NSDefaultRunLoopMode  :
優先級更低
 NSRunLoopCommonModes
 */

// 提升 timer的優先級
[mainLoop addTimer:_timer forMode:NSRunLoopCommonModes];

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章