计算凸起畸变过滤器半径的收缩值
Calculate pinch value for bulge distortion filter radius
我需要根据捏合来增加和减小 GPUImagePinchDistortionFilter
半径,我正在使用捏合手势识别器并存储手势识别器的起始比例。我需要计算 -2.0 和 2.0 之间的收缩比例。这是我的代码。
if([gestureRecognizer state] == UIGestureRecognizerStateBegan) {
lastScale = [gestureRecognizer scale];
}
if ([gestureRecognizer state] == UIGestureRecognizerStateBegan ||
[gestureRecognizer state] == UIGestureRecognizerStateChanged) {
CGFloat currentScale = [[[gestureRecognizer view].layer valueForKeyPath:@"transform.scale"] floatValue];
CGFloat kMaxScale = 2.0;
CGFloat kMinScale = -2.0;
CGFloat newScale = 1.0 - (lastScale - [gestureRecognizer scale]);
newScale = MIN(newScale, kMaxScale / currentScale);
newScale = MAX(newScale, kMinScale / currentScale);
[pinchDistortionFilter setRadius:newScale];
}
我关注了一些帖子来做到这一点。但仍然卡住了,每次用户捏时我都需要设置它,但半径必须在最小和最大范围内。实际上我很困惑如何实现这一点,谁能帮我解决这个问题?
谢谢。
我认为你应该尝试将 lastScale 和半径也保存在正确的位置,并且半径应该 > 0 请参阅下面的答案以了解我的实现,它可能会对你有所帮助。
float currentApplicableScale = (gestureRecognizer.scale/2);
if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {
lastRadius = lastScale;
}else if (gestureRecognizer.state==UIGestureRecognizerStateBegan) {
firstScale = currentApplicableScale;
}else if (gestureRecognizer.state == UIGestureRecognizerStateChanged) {
float radius = currentApplicableScale;
if (lastRadius<=0) {
lastRadius = 0.25;
}
radius = radius - (firstScale - lastRadius);
if (radius>0 && radius < 0.5) {
[(GPUImagePinchDistortionFilter*)pinchFilter setRadius:radius];
lastScale = radius; //Save here
}
}
我需要根据捏合来增加和减小 GPUImagePinchDistortionFilter
半径,我正在使用捏合手势识别器并存储手势识别器的起始比例。我需要计算 -2.0 和 2.0 之间的收缩比例。这是我的代码。
if([gestureRecognizer state] == UIGestureRecognizerStateBegan) {
lastScale = [gestureRecognizer scale];
}
if ([gestureRecognizer state] == UIGestureRecognizerStateBegan ||
[gestureRecognizer state] == UIGestureRecognizerStateChanged) {
CGFloat currentScale = [[[gestureRecognizer view].layer valueForKeyPath:@"transform.scale"] floatValue];
CGFloat kMaxScale = 2.0;
CGFloat kMinScale = -2.0;
CGFloat newScale = 1.0 - (lastScale - [gestureRecognizer scale]);
newScale = MIN(newScale, kMaxScale / currentScale);
newScale = MAX(newScale, kMinScale / currentScale);
[pinchDistortionFilter setRadius:newScale];
}
我关注了一些帖子来做到这一点。但仍然卡住了,每次用户捏时我都需要设置它,但半径必须在最小和最大范围内。实际上我很困惑如何实现这一点,谁能帮我解决这个问题?
谢谢。
我认为你应该尝试将 lastScale 和半径也保存在正确的位置,并且半径应该 > 0 请参阅下面的答案以了解我的实现,它可能会对你有所帮助。
float currentApplicableScale = (gestureRecognizer.scale/2);
if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {
lastRadius = lastScale;
}else if (gestureRecognizer.state==UIGestureRecognizerStateBegan) {
firstScale = currentApplicableScale;
}else if (gestureRecognizer.state == UIGestureRecognizerStateChanged) {
float radius = currentApplicableScale;
if (lastRadius<=0) {
lastRadius = 0.25;
}
radius = radius - (firstScale - lastRadius);
if (radius>0 && radius < 0.5) {
[(GPUImagePinchDistortionFilter*)pinchFilter setRadius:radius];
lastScale = radius; //Save here
}
}