我正在尝试在我的目标 c 代码中包含一个力组件,因为它现在应该可以从 ios9 开始。我的代码包含以下两种方法:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
在 touchesEnded 方法中,我尝试使用以下代码行来获取触摸事件的力量:
for (UITouch *touch in touches) {
CGFloat force = touch.force;
CGFloat percentage = force/touch.maximumPossibleForce;
NSLog(@"Printing force : %f", force);
NSLog(@"Printing percentage: %f", percentage);
NSLog(@"Printing maximum possible force: %f", touch.maximumPossibleForce);
break;
}
我试图在 iphone 6s 上运行我的代码,我得到了非常奇怪和矛盾的值,例如 force : 2.650000 和 force : 0.066667 即使我认为我几乎以同样的力量按下按钮。
我不想实现 peek 和 pop,而只是让用户通过一个按钮来控制具有不同选项的应用程序。
非常感谢你!