要打滑View参加UIPanGestureRecognizer

#pragma mark 手势识别器回调方法

- (void)dragView:(UIPanGestureRecognizer *)gesture{

switch (gesture.state) {

case
UIGestureRecognizerStateBegan:

[self
startDrag];

break;

case
UIGestureRecognizerStateEnded:

[self
endDrag];

break;

default:

[self
Draging:gesture];

break;

}

}

#pragma mark 開始拖动,记录下開始的x值

- (void)startDrag{

CGRect frame = _mainView.frame;

_lastDownX = frame.origin.x;

}

#pragma mark 正在拖动,让View跟着动

- (void)Draging:(UIPanGestureRecognizer *)gesture{

CGFloat maxX = [UIScreen
mainScreen].bounds.size.width *
kSlideRatio;

CGPoint transform = [gesture
translationInView:_mainView];

CGRect frame = _mainView.frame;

frame.origin.x =
_lastDownX + transform.x;

if (frame.origin.x <
) {   //不能够移动到屏幕左边去

frame.origin.x =
;

}else
if(frame.origin.x > maxX){

frame.origin.x = maxX; 
//限制移动的最右边

}

_mainView.frame = frame;

//
设置界面scale动画

CGFloat tx = frame.origin.x;

) {

tx =
;

}

CGFloat txScale = tx /
_settingsViewController.view.frame.size.width;

//
让imageview缩放

double scale =
kDefaultSettingScale -
kDefaultSettingScale);

){

scale =
;

}

CGAffineTransform cgTransform =
CGAffineTransformMakeScale(scale, scale);

[_settingsViewController
setAnimationScale:cgTransform];

}

#pragma mark 拖动结束,推断要往哪边滚动

- (void)endDrag{

int maxX = [self
getSettingRight];

int currentX = _mainView.frame.origin.x;

if (currentX < maxX *
0.5) {    //没到一半,回到左边

currentX =
;

}else{     
//回到右边

currentX = maxX;

}

CGRect frame = _mainView.frame;

frame.origin.x = currentX;

[self
scrollMainViewToFrame:frame withDuration:0.25];

}

版权声明:本文博主原创文章,博客,未经同意不得转载。

05-12 00:57