我需要在iOS中使用滑動手勢做頁面捲曲。如何在iOS中使用滑動手勢卷頁?
我已經研究了葉子項目(https://github.com/brow/leaves),但它不支持滑動手勢。
有沒有人成功實現了頁面捲曲的輕掃手勢?
謝謝。
我需要在iOS中使用滑動手勢做頁面捲曲。如何在iOS中使用滑動手勢卷頁?
我已經研究了葉子項目(https://github.com/brow/leaves),但它不支持滑動手勢。
有沒有人成功實現了頁面捲曲的輕掃手勢?
謝謝。
對於頁面捲曲,您可以使用視圖過渡動畫。對於滑動手勢,請查看使用新的手勢識別器類。您還可以設置當您展示新的模式視圖控制器以獲得其他過渡樣式時的過渡樣式。
我不知道頁面捲曲的方面,我不熟悉葉子,但你可以看看UISwipeGestureRecognizer
類文檔,瞭解更多信息。也許你可以擴展葉子源代碼。
使用UISwipeGestureRecognizer。沒有什麼可說的,手勢識別器很容易。甚至有關於該主題的WWDC10視頻。會話120和121
蘋果當然使用OpenGL ES來實現它。 Apple實際使用的API是私有的,但這個blogger具有示例代碼實現的開始。所以,現在你只需幾次點擊即可在自定義輕掃手勢內執行頁面捲曲。
使用UISwipeGestureRecognizer和UIViewAnimationTransition
- (void)handleSwipe:(UISwipeGestureRecognizer *)sender {
if(sender.state == UIGestureRecognizerStateEnded) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:window cache:YES];
[self.view addSubview:[newView view]];
[oldView removeFromSuperview];
[UIView commitAnimations];
}
}
- (void)createGestureRecognizers:(UIView *) target {
UISwipeGestureRecognizer *rightSwipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
[rightSwipeRecognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
[target addGestureRecognizer:rightSwipeRecognizer];
[rightSwipeRecognizer release];
}
這工作不錯。只需要輕掃一下動畫就會很完美。 – jroyce 2012-03-20 21:39:52