gpt4 book ai didi

ios - 如何从起点和滚动点找到终点坐标

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:40:50 28 4
gpt4 key购买 nike

我必须从起点和移动点找到端点。

我正在制作动画,当用户拖动 View 时我需要移动 View 然后我必须通过它离开屏幕并返回到原始点。

现在我使用 UISwipeGestureRecognizer 来检测移动时的滑动。以下是代码。

 UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];

// Setting the swipe direction.
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
[swipeUp setDirection:UISwipeGestureRecognizerDirectionUp];
[swipeDown setDirection:UISwipeGestureRecognizerDirectionDown];

// Adding the swipe gesture on image view
[_view1 addGestureRecognizer:swipeLeft];
[_view1 addGestureRecognizer:swipeRight];
[_view1 addGestureRecognizer:swipeUp];
[_view1 addGestureRecognizer:swipeDown];

处理滑动

- (void)handleSwipe:(UISwipeGestureRecognizer *)swipe {

CGPoint movedPoint = [swipe locationInView:swipe.view];

if (swipe.direction == UISwipeGestureRecognizerDirectionLeft) {
NSLog(@"Left Swipe");

CGPoint startPoint = _view1.frame.origin;
//Diffence Moved
float movedDiffence_X = startPoint.x - movedPoint.x;
float movedDiffence_Y = startPoint.y - movedPoint.y;
//How can I find END POINT BASED ON THIS DATA

[UIView animateWithDuration:1 animations:^{
_view1.center = CGPointMake(movedDiffence_X *3,movedDiffence_Y *3 );
_view1.transform = CGAffineTransformMakeRotation(-0.86);
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.8 animations:^{
_view1.center = CGPointMake(84, 240);
_view1.transform = CGAffineTransformMakeRotation(0.36);
} completion:^(BOOL finished) {

}];
}];

}
if (swipe.direction == UISwipeGestureRecognizerDirectionRight) {
NSLog(@"Right Swipe");
CGPoint startPoint = _view1.frame.origin;
//Diffence Moved
float movedDiffence_X = startPoint.x - movedPoint.x;
float movedDiffence_Y = startPoint.y - movedPoint.y;

//How can I find

[UIView animateWithDuration:1 animations:^{
_view1.center = CGPointMake(movedDiffence_X *3,movedDiffence_Y *3 );
_view1.transform = CGAffineTransformMakeRotation(-0.86);
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.8 animations:^{
_view1.center = CGPointMake(84, 240);
_view1.transform = CGAffineTransformMakeRotation(0.36);
} completion:^(BOOL finished) {

}];
}];
}

if (swipe.direction == UISwipeGestureRecognizerDirectionUp) {
NSLog(@"Up Swipe");

CGPoint startPoint = _view1.frame.origin;
//Diffence Moved
float movedDiffence_X = startPoint.x - movedPoint.x;
float movedDiffence_Y = startPoint.y - movedPoint.y;

//How can I find

[UIView animateWithDuration:1 animations:^{
_view1.center = CGPointMake(movedDiffence_X *3,movedDiffence_Y *3 );
_view1.transform = CGAffineTransformMakeRotation(-0.86);
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.8 animations:^{
_view1.center = CGPointMake(84, 240);
_view1.transform = CGAffineTransformMakeRotation(0.36);
} completion:^(BOOL finished) {

}];
}];
}
if (swipe.direction == UISwipeGestureRecognizerDirectionDown) {
NSLog(@"Down Swipe");

CGPoint startPoint = _view1.frame.origin;
//Diffence Moved
float movedDiffence_X = startPoint.x - movedPoint.x;
float movedDiffence_Y = startPoint.y - movedPoint.y;

//How can I find

[UIView animateWithDuration:1 animations:^{
_view1.center = CGPointMake(movedDiffence_X *3,movedDiffence_Y *3 );
_view1.transform = CGAffineTransformMakeRotation(-0.86);
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.8 animations:^{
_view1.center = CGPointMake(84, 240);
_view1.transform = CGAffineTransformMakeRotation(0.36);
} completion:^(BOOL finished) {

}];
}];
}

}

enter image description here

当我滑动第一 View 时,我可以在 SwipeHandler (handleSwipe) 方法中移动点

所以我也可以检测滑动方向。但我的问题是我必须通过屏幕外的 No.1 View。为此,我必须找到端点。

那么,如何从 Starting point 和 MovedPoint 找到 Endpoint 呢?

最佳答案

关于ios - 如何从起点和滚动点找到终点坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18569570/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com