gpt4 book ai didi

iOS Animate 使用手势将 ImageView 从屏幕外滑动到屏幕上

转载 作者:行者123 更新时间:2023-12-01 19:17:00 26 4
gpt4 key购买 nike

我正在寻找带有文字的气泡动画,以在屏幕上滑动和滑出。此动画的理想实现是启用分页的 iOS 水平滚动。当我到达语音气泡的末尾时,我绝对想要“反弹”,并且我绝对希望气泡跟踪手指直到它们滑出屏幕之前的某个点。我相信这与滑动不同(这只是一个方向的轻弹)。

然而,水平滚动的问题在于它针对静态数量的图像进行了优化。我将拥有动态数量的图像,据我所知,您不能将图像动态附加到水平滚动条。这个想法是应用程序在您继续浏览滚动条时动态地将内容添加到滚动条中。

卷轴很容易上手,但我现在必须把它拆掉。我怎样才能开始使用手势(我不确定标准手势识别器此时是否对我有用)以及动画?我以前从未使用过这部分 iOS 代码。

最佳答案

我不确定我是否完全遵循您的问题,但如果您想根据手势为某物的运动设置动画,您可以使用 UIPanGestureRecognizer并更改 center您想要的任何 subview 。例如,在 viewDidLoad你会:

UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(movePiece:)];
[whateverViewYouWantToAnimate addGestureRecognizer:panGesture];

然后,您可以让手势识别器将其移动到您想要的任何位置:
- (void)movePiece:(UIPanGestureRecognizer *)gestureRecognizer
{
static CGPoint originalCenter;

if (gestureRecognizer.state == UIGestureRecognizerStateBegan)
{
originalCenter = [gestureRecognizer view].center;
}
else if (gestureRecognizer.state == UIGestureRecognizerStateChanged)
{
CGPoint translation = [gestureRecognizer translationInView:self.view];

gestureRecognizer.view.center = CGPointMake(originalCenter.x + translation.x, originalCenter.y);

// if you wanted to animate both left/right and up/down, it would be:
// gestureRecognizer.view.center = CGPointMake(originalCenter.x + translation.x, originalCenter.y + translation.y);
}
else if (gestureRecognizer.state == UIGestureRecognizerStateEnded)
{
// replace this offscreen CGPoint with something that makes sense for your app

CGPoint offscreen = CGPointMake(480, gestureRecognizer.view.center.y);

[UIView animateWithDuration:0.5
animations:^{
gestureRecognizer.view.center = offscreen;
}
completion:^(BOOL finished){
// when you're done, you might want to do whatever cleanup
// is appropriate for your app (e.g. do you want to remove it?)
[gestureRecognizer.view removeFromSuperview];
}];
}
}

关于iOS Animate 使用手势将 ImageView 从屏幕外滑动到屏幕上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12647017/

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