gpt4 book ai didi

ios - 当他们向下移动屏幕时从左到右移动 UIView

转载 作者:行者123 更新时间:2023-11-28 22:36:01 25 4
gpt4 key购买 nike

我正在尝试创建一个 iOS 应用程序,其中 block 在屏幕上 float (UIViews)。我让它们在屏幕上漂浮,但我也希望用户能够在它们下落时在 x 轴上移动它们。我试着用下面的代码来做,但它们只是掉下来,不会从左到右移动。我的问题是我试图用手指从左向右移动它,因为它已经在屏幕上移动了。我怎样才能使下面的代码生效?

注意:我能够将 View 从左向右移动而无需将它们向下移动到屏幕上,并且我能够将它们向下移动到屏幕上而不将它们从左向右移动。当我将两者结合时,问题就出现了。

Y 轴动画

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:letView.speed];
[UIView setAnimationDelay:0.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

letView.layer.frame = CGRectMake(letView.layer.frame.origin.x, [[UIScreen mainScreen] bounds].size.height, letView.layer.frame.size.width, letView.layer.frame.size.height);

[UIView commitAnimations];

触摸动画

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self.view];
//Goes through an array of views to see which one to move
for (LetterView * view in _viewArray) {
if (CGRectContainsPoint(view.frame, touchLocation)) {
dragging = YES;
currentDragView = view;
[currentDragView.layer removeAllAnimations];
}
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self.view];
if (dragging) {
CGPoint location = touchLocation;
currentDragView.center = CGPointMake(location.x, currentDragView.center.y);
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
dragging = NO;
[self checkForCorrectWord];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:currentDragView.speed];
[UIView setAnimationDelay:0.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
currentDragView
.layer.frame = CGRectMake(currentDragView.layer.frame.origin.x, [[UIScreen mainScreen] bounds].size.height, currentDragView.layer.frame.size.width, currentDragView.layer.frame.size.height);

[UIView commitAnimations];
}

最佳答案

我有一个演示项目,向您展示如何使“船”在屏幕上以 S 曲线动画,如下所示:

enter image description here

我使用的解决方案是制作一个关键帧动画(实际上它是构成分组动画一部分的关键帧动画,但您可能不需要分组动画的其余部分:它是关键帧制作弯曲路径形状的动画)。或许你可以调整我正在做的事情,根据你自己的目的修改它?

代码可在此处下载:

https://github.com/mattneub/Programming-iOS-Book-Examples/tree/master/ch17p501groupedAnimation

在我的书中有详细讨论。关键帧动画一般:

http://www.apeth.com/iOSBook/ch17.html#_keyframe_animation

这个特殊的例子:

http://www.apeth.com/iOSBook/ch17.html#_grouped_animations

关于ios - 当他们向下移动屏幕时从左到右移动 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16001385/

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