gpt4 book ai didi

ios - 下一次触摸前未能收到系统手势状态通知

转载 作者:IT王子 更新时间:2023-10-29 08:16:37 26 4
gpt4 key购买 nike

我有一个控件可以在一个 View 中交替切换两个 View 。即,在容器 View 中通过 subview 方法添加了两个 View Controller 。双指张开手势放大当前 View ,并显示第二个 View 。如果想转到上一个 View ,捏出手势即可。问题是, View 有时并不总是对 gusture 和消息使用react

"Failed to receive system gesture state notification before next touch"

在日志中打印出来。有什么建议为什么会出现此消息并且 View 无法识别该手势吗?

- (void)scaleHandler:(UIPinchGestureRecognizer *)gestureRecognizer{

CGFloat currentScale = [[[gestureRecognizer view].layer valueForKeyPath:@"transform.scale"] floatValue];
if([gestureRecognizer state] == UIGestureRecognizerStateBegan) {
// Reset the last scale, necessary if there are multiple objects with different scales
lastScale = [gestureRecognizer scale];
}

if ([gestureRecognizer state] == UIGestureRecognizerStateBegan ||
[gestureRecognizer state] == UIGestureRecognizerStateChanged) {

// Constants to adjust the max/min values of zoom
CGFloat kMaxScale = 1.0;
CGFloat kMinScale = 1.0;
gestureRecognizer.view.alpha = 1/currentScale;
if ([gestureRecognizer view] == [self.firstView view]) {
kMaxScale = 10.0;
kMinScale = 1.0;
gestureRecognizer.view.alpha = 1/currentScale;
}

if ([gestureRecognizer view] == [self.pageView view]) {
kMaxScale = 1.0;
kMinScale = 0.1;
gestureRecognizer.view.alpha = currentScale;
}


// NSLog(@"Current Scale is %f",[gestureRecognizer scale]);

CGFloat newScale = 1 - (lastScale - [gestureRecognizer scale]);
newScale = MIN(newScale, kMaxScale / currentScale);
newScale = MAX(newScale, kMinScale / currentScale);

CGAffineTransform transform = CGAffineTransformScale([[gestureRecognizer view] transform], newScale, newScale);
[gestureRecognizer view].transform = transform;

lastScale = [gestureRecognizer scale]; // Store the previous scale factor for the next pinch gesture call
}

if([gestureRecognizer state] == UIGestureRecognizerStateEnded){

if ([gestureRecognizer view] == [self.firstView view]) {
if(currentScale > 1.0f){
[self setPinchOutAnimationHidden:YES];
}
else{
[self setPinchOutAnimationHidden:NO];
}
}
else{
if(currentScale < 0.9f){
[self setPinchInAnimationToHidden:YES];
}
else{
[self setPinchInAnimationToHidden:NO];
}
}

}

}

- (void)setPinchInAnimationToHidden: (BOOL)shouldHide{

if(shouldHide){
NSLog(@"animation 1 - pinch in");
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
CGAffineTransform transform = CGAffineTransformScale([self.pageView.view transform], 0, 0);
self.pageView.view.transform = transform;
} completion:^(BOOL finished){
// [firstView.view sendSubviewToBack:pageView.view];
NSLog(@"animation 1 - pinchin completion handler");
[self.view insertSubview:self.pageView.view belowSubview:self.firstView.view];
self.pageView.view.transform = CGAffineTransformMakeScale(1.0, 1.0);
self.pageView.view.alpha = 1.0;
}];
}
else{
NSLog(@"animation 2- pinch in");
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
self.pageView.view.transform = CGAffineTransformMakeScale(1.0, 1.0);
self.pageView.view.alpha = 1.0;
} completion:nil];
}
}

- (void)setPinchOutAnimationHidden: (BOOL)shouldHide{
if(shouldHide){
NSLog(@"animation 3 - pinch out");
// firstView = [ViewFactory firstViewController];
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
CGAffineTransform transform = CGAffineTransformScale([self.firstView.view transform], 15.0, 15.0);
self.firstView.view.transform = transform;
self.firstView.view.alpha = 0.0;
} completion:^(BOOL finished){
NSLog(@"animation 3 - pinch out - completion handler");
//[pageView.view sendSubviewToBack:firstView.view];
[self.view insertSubview:self.firstView.view belowSubview:self.pageView.view];
self.firstView.view.transform = CGAffineTransformMakeScale(1.0, 1.0);
self.firstView.view.alpha = 1.0;
}];
}
else{
NSLog(@"animation 4- pinch out");
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
self.firstView.view.transform = CGAffineTransformMakeScale(1.0, 1.0);
self.firstView.view.alpha = 1.0;
} completion:nil];
}
}

最佳答案

view doesn't recogonize the gesture

注册您的手势以识别状态

UIPinchGestureRecognizer *pinchGestureRecog = [UIPinchGestureRecognizer alloc]initWithTarget:self action: @selector(scaleHandler:)];

关于ios - 下一次触摸前未能收到系统手势状态通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19765012/

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