gpt4 book ai didi

cordova - 类似 Instagram 的强制触摸弹出模式

转载 作者:行者123 更新时间:2023-12-02 08:10:53 27 4
gpt4 key购买 nike

我正在尝试复制 Instagram 的强制触摸功能,其中

1)将手指放在图像上,图像会变暗(悬停效果,简单)

2)稍微用力按下,就会出现内容的弹出模式预览

3)用力按压,模式将扩展到全屏

我在使用 Ionic 4/Cordova“3d touch”插件时遇到问题,如果我先常规触摸屏幕,它不会注册强制触摸。

换言之,通过 thirdDeeTouch.watchForceTouches() 监听时,上述步骤 2 不会触发强制触摸

为了让听者触发,我必须首先用力进行触摸,在“触摸”屏幕和“按下”屏幕之间没有任何延迟。如果我触摸屏幕但没有按下它,我将无法再在不先抬起手指的情况下按下它来触发强制触摸。

我正在真实设备 iPhone X 上进行测试

如何解决此问题以在 Instagram 中复制强制触摸?

最佳答案

我也在 ionic cordova 应用程序中尝试了相同的操作,请尝试查看下面的内容以进一步进行

watchForceTouches() : You can get a notification when the user force touches the webview. The plugin defines a Force Touch when at least 75% of the maximum force is applied to the screen. Your app will receive the x and y coordinates, so you have to figure out which UI element was touched.

我已经尝试过这种语法,并通过降级插件版本以及以下代码集来实现它

    @implementation ForceTouchRecognizer

double lastEvent = 0;

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch* touch in touches) {
CGFloat percentage = (touch.force / touch.maximumPossibleForce) * 100;
if (percentage >= 75) {
// let's not flood the callback with multiple hits within the same second
NSTimeInterval ts = touch.timestamp;
int diff = ts - lastEvent;
if (diff > 0) {
lastEvent = ts;
CGPoint coordinates = [touch locationInView:self.view];
NSMutableDictionary *result = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
[NSString stringWithFormat:@"%d", (int)percentage] , @"force",
[NSString stringWithFormat:@"%d", (int)coordinates.x], @"x",
[NSString stringWithFormat:@"%d", (int)coordinates.y], @"y",
// no need to use the touch.timestamp really since it's simply 'now'
[NSString stringWithFormat:@"%f", [[NSDate date] timeIntervalSince1970]], @"timestamp",
nil];

CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:result];
pluginResult.keepCallback = [NSNumber numberWithBool:YES];
[_commandDelegate sendPluginResult:pluginResult callbackId:_callbackId];
}
}
}
}
@end

关于cordova - 类似 Instagram 的强制触摸弹出模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54897455/

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