翻頁效果,類似下面的樣子:
在電子書應用中會很常見。這裡需要兩個要點:
先說一下輕掃(swipe)的實現,可以參考編寫簡單的手勢示例:tap了解手勢種類。
在viewdidload方法中註冊了對上、下、左、右四個方向輕鬆的處理方法:
- (void)viewdidload {可以看到,都是同乙個方法,handleswipefrom。uiswipegesturerecognizer *recognizer;
recognizer = [[uiswipegesturerecognizer alloc] initwithtarget:self action:@selector(handleswipefrom:)];
[recognizer setdirection:(uiswipegesturerecognizerdirectionright)];
[[self view] addgesturerecognizer:recognizer];
[recognizer release];
recognizer = [[uiswipegesturerecognizer alloc] initwithtarget:self action:@selector(handleswipefrom:)];
[recognizer setdirection:(uiswipegesturerecognizerdirectionup)];
[[self view] addgesturerecognizer:recognizer];
[recognizer release];
recognizer = [[uiswipegesturerecognizer alloc] initwithtarget:self action:@selector(handleswipefrom:)];
[recognizer setdirection:(uiswipegesturerecognizerdirectiondown)];
[[self view] addgesturerecognizer:recognizer];
[recognizer release];
recognizer = [[uiswipegesturerecognizer alloc] initwithtarget:self action:@selector(handleswipefrom:)];
[recognizer setdirection:(uiswipegesturerecognizerdirectionleft)];
[[self view] addgesturerecognizer:recognizer];
[recognizer release];
[super viewdidload];
在該方法中,再識別具體是哪個方向的輕掃手勢,比如判斷是向下的輕掃:
-(void)handleswipefrom:(uiswipegesturerecognizer *)recognizer {判斷是向上的輕掃:nslog(@"swipe received.");
if (recognizer.direction==uiswipegesturerecognizerdirectiondown) {
nslog(@"swipe down");
if (recognizer.direction==uiswipegesturerecognizerdirectionup) {有關動畫的處理,比如向下(往回)翻頁,類似這樣:nslog(@"swipe up");
[uiview beginanimations:@"animationid" context:nil];向上(向前)翻頁,只需改為:[uiview setanimationduration:0.7f];
[uiview setanimationcurve:uiviewanimationcurveeaseinout];
[uiview setanimationrepeatautoreverses:no];
[uiview setanimationtransition:uiviewanimationtransitioncurldown forview:self.view cache:yes];
[currentview removefromsuperview];
[self.view addsubview:contentview];
[uiview commitanimations];
[uiview beginanimations:@"animationid" context:nil];這樣,寫一套翻頁**和載入什麼圖形之間就可以解耦。[uiview setanimationduration:0.7f];
[uiview setanimationcurve:uiviewanimationcurveeaseinout];
[uiview setanimationrepeatautoreverses:no];
[uiview setanimationtransition:uiviewanimationtransitioncurlupforview:self.view cache:yes];
[currentview removefromsuperview];
[self.view addsubview:contentview];
[uiview commitanimations];
儲存在resources下。
為了能讓上頁下頁翻頁的時候找到關聯的頁面,採用了如下機制:
比如這樣,當應用載入的時候顯示第一頁:
在翻頁時的處理:
編寫簡單的翻頁效果
翻頁效果,類似下面的樣子 在電子書應用中會很常見。這裡需要兩個要點 先說一下輕掃 swipe 的實現,可以參考編寫簡單的手勢示例 tap了解手勢種類。在viewdidload方法中註冊了對上 下 左 右四個方向輕鬆的處理方法 void viewdidload uiswipegesturerecogn...
Iphone實現簡單翻頁效果
經常看到iphone的軟體向上向下翻頁面的效果,其實這個很簡單,已經有封裝好的相關方法處理。首先設定動畫的相關引數 uiview beginanimations curl context nil uiview setanimationduration 1.25 時間 uiviewsetanimati...
jquery無重新整理翻頁,無翻頁效果
前台 名稱 nc2 httputility.urlencode 值 class lk mw 更多 一般處理程式 using system using system.collections using system.data using system.web using system.web.serv...