http://www.cocoachina.com/iphonedev/toolthain/2011/1222/3768.html
源码由论坛会员zgrubby分享
实现了大部分Path 2.0 特效
注(iOS5 only),文章最后有源码下载
tableview添加手势检测代码
- (
void
)awakeFromNib{
UIPanGestureRecognizer* recognizer;
// handleSwipeFrom 是偵測到手势,所要呼叫的方法
recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:
self
action:
@selector
(handlePanFrom:)];
// 不同的 Recognizer 有不同的实体变数
// 例如 SwipeGesture 可以指定方向
// 而 TapGesture 則可以指定次數
//recognizer.direction = UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight;
recognizer.delegate =
self
;
[_tableView addGestureRecognizer:recognizer];
[recognizer release];
}
- (
BOOL
)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer
{
CGPoint translation = [gestureRecognizer translationInView:[[UIApplication sharedApplication] keyWindow]];
// Check for horizontal gesture
if
(sqrt(translation.x * translation.x) / sqrt(translation.y * translation.y) > 1)
{
return
YES
;
}
return
NO
;
}
- (
void
)handlePanFrom:(UIPanGestureRecognizer*)recognizer {
if
(recognizer.state == UIGestureRecognizerStateBegan) {
;
}
else
if
(recognizer.state == UIGestureRecognizerStateChanged) {
CGFloat xOffSet = [recognizer translationInView:[[UIApplication sharedApplication] keyWindow]].x;
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if
(xOffSet < 0) {
[appDelegate makeRightViewVisible];
}
else
if
(xOffSet > 0) {
[appDelegate makeLeftViewVisible];
}
self
.navigationController.view.frame = CGRectMake(xOffSet,
self
.navigationController.view.frame.origin.y,
self
.navigationController.view.frame.size.width,
self
.navigationController.view.frame.size.height);
}
else
if
(recognizer.state == UIGestureRecognizerStateEnded) {
if
(
self
.navigationController.view.frame.origin.x < -kTriggerOffSet)
[
self
moveToLeftSide];
// animate to right side
else
if
(
self
.navigationController.view.frame.origin.x > kTriggerOffSet)
[
self
moveToRightSide];
// reset
else
[
self
restoreViewLocation];
}
}
![](http://www.cocoachina.com/cms/uploads/allimg/111222/3292_111222163043_1.png)
![](http://www.cocoachina.com/cms/uploads/allimg/111222/3292_111222163058_1.png)
![](http://www.cocoachina.com/cms/uploads/allimg/111222/3292_111222163050_1.png)
源码下载:
![]() | Path2DemoPrj |