gpt4 book ai didi

iphone - 使用平移的 UIImageView 移动不完全平滑

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:09:14 25 4
gpt4 key购买 nike

我正在开发一个简单的图像交换应用程序,类似于 Tinder 的用户界面,用户可以使用平移手势交换/导航图像。我遇到了一个小问题,这真的困扰着我,我真的不明白为什么会这样——因为我的平移方法工作正常,它似乎仍然不像 tinder 的那样“平滑”。 uiimageview 的动画/重绘不是那么清晰,我不明白为什么。我的代码是相当教科书式的平移方法:

-(void)HandlePan:(UIGestureRecognizer *)recognizer{


CGPoint translation = [recognizer translationInView:self.view];

[UIView animateWithDuration:0.1 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{[recognizer.view setCenter:(CGPointMake(recognizer.view.center.x+translation.x * 1.50,recognizer.view.center.y +translation.y* 1.50))];} completion:nil];

CGPoint leftOutOfBounds = CGPointMake(-160, 160);
CGPoint rightOutOfBounds = CGPointMake(480, 160);

CGPoint velocity = [recognizer velocityInView:self.view];

if(_imagePreviewerTop.center.x > self.view.center.x){



if(velocity.x > 0){
swipeTransform = swipeTransform+.005;
[_decisionLabel setText:@"UPVOTE"];
[_decisionLabel setBackgroundColor:[UIColor successColor]];
[_decisionLabel setTextColor:[UIColor whiteColor]];
}
else if (velocity.x < 0){
swipeTransform = swipeTransform-.005;
}
[_imagePreviewerTop setTransform:CGAffineTransformMakeRotation(swipeTransform)];



}
else if(_imagePreviewerTop.center.x < self.view.center.x){
//NSLog(@"gesture went left");


if(velocity.x < 0){
swipeTransform = swipeTransform-.005;
[_decisionLabel setText:@"PASS"];
[_decisionLabel setBackgroundColor:[UIColor infoBlueColor]];
[_decisionLabel setTextColor:[UIColor whiteColor]];
}
else if(velocity.x > 0){
swipeTransform = swipeTransform+.005;
//NSLog(@"gesture went left");

}
[_imagePreviewerTop setTransform:CGAffineTransformMakeRotation(swipeTransform)];


}



[recognizer setTranslation:CGPointMake(0, 0) inView:self.view];

if(recognizer.state == UIGestureRecognizerStateEnded){
//implement repositioning here

if (_imagePreviewerTop.center.x <50){
//"finger lifted on left"

[UIView animateWithDuration:.25 animations:^{_imagePreviewerTop.center = leftOutOfBounds;
} completion:^(BOOL isFinished){
if (isFinished == true) {
[self changeImage:@"0"];




}
}];
}


else if (_imagePreviewerTop.center.x > 270){
//"finger lifted on right"
//[self.view addSubview:_upVote];
[UIView animateWithDuration:.25 animations:^{_imagePreviewerTop.center = rightOutOfBounds; } completion:^(BOOL isFinished){
if (isFinished == true) {
[self changeImage:@"1"];

}
}];
}
else{

[UIView animateWithDuration:.5 animations:^{_imagePreviewerTop.center =_imagePreviewerBottom.center;[_imagePreviewerTop setTransform:CGAffineTransformMakeRotation(0.0)];swipeTransform = 0;} completion:^(BOOL isFinished){
if (isFinished == true) {
[_decisionLabel setText:@"start swiping!"];
[_decisionLabel setBackgroundColor:[UIColor babyBlueColor]];
[_decisionLabel setTextColor:[UIColor infoBlueColor]];

}
}];
}
}


}

还有什么我应该做的吗?我下面还有一些代码处理图像的速度和位置,但我认为这与问题无关。我还尝试了其他一些实现“拖动”感觉的方法,但它们似乎都没有100% 平滑。

任何帮助将不胜感激,谢谢!

最佳答案

在做了一些研究之后,我发现由于我使用 iOS 的核心图形(圆角、阴影等)绘制了相当复杂的 View ,因此解决方案是将 View 的“shouldRasterize”属性设置为 YES 并修复问题。

谢谢和 gl。

关于iphone - 使用平移的 UIImageView 移动不完全平滑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18192299/

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