答えて
私はあなたが新しいタプティックエンジンについて話していると思います。
apple.comから:iPhone 6sは、タップエンジンから、画面上と微妙なタップの両方でリアルタイムのフィードバックを提供します。これらの反応は、あなたがディスプレイをどれくらい深く押しているかに対応しており、実行しているアクションと起こることが期待できることを知らせます。
私が実際に知っているように、そのための公開APIはありません。 プライベートAPI経由でタプティックフィードバックを実装するために私はthis tutorialしか見つけていません。
//ATTENTION: This is a private API, if you use this lines of code your app will be rejected
id tapticEngine = [[UIDevice currentDevice] performSelector:NSSelectorFromString(@"_tapticEngine") withObject:nil];
[tapticEngine performSelector:NSSelectorFromString(@"actuateFeedback:") withObject:@(0)];
あなたはこれを達成するためのカスタムロジックを使用することができます。
- は
UITouch
クラスのforce
とmaximumPossibleForce
プロパティを使用して、ユーザーが画面上に加わる力を検出します。 - 力量に応じて、特定のレベルの後にデバイスを振動させることができます。
例:
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
[super touchesMoved:touches withEvent:event];
UITouch *touch = [touches anyObject];
CGFloat maximumPossibleForce = touch.maximumPossibleForce;
CGFloat force = touch.force;
CGFloat normalizedForce = force/maximumPossibleForce;
NSLog(@"Normalized force : %f", normalizedForce);
if (normalizedForce > 0.75)
{
NSLog(@"Strong");
// Vibrate device
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
else
{
NSLog(@"Weak");
}
}
- また、カスタム・ロジックと異なる力レベル毎に異なる振動時間を設定してみてください。
例:UIFeedbackGenerator
:iOSの10以降で
// Vibrate device
NSTimer * vibrationTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(vibrateDevice) userInfo:nil repeats:YES];
- (void) vibrateDevice
{
if(duration == 2) // duration is a public variable to count vibration duration
{
// Stop the device vibration
[vibrationTimer invalidate];
return;
}
duration++;
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
、触覚フィードバックを処理するための新しいパブリックAPIがあります。
let generator = UINotificationFeedbackGenerator()
generator.notificationOccurred(.success)
発電機を使用して「ウェイクアップ」が必要なフィードバックハードウェアによる2との間にわずかな遅延があるようにフィードバックを送信する前に、.prepare()
を呼び出すことが示唆されています。これは、viewDidLoad()
や、まもなくフィードバックが来ることを期待している場合に比較できるもので行うことができます。
は、新しいAPIの良い説明し、利用可能なフィードバックのために、このブログを参照してください。他の記事で概説したよう
https://www.hackingwithswift.com/example-code/uikit/how-to-generate-haptic-feedback-with-uifeedbackgenerator
iOSの9の場合と古い、あなたはAudioToolBoxを使用することができます。 (iPhone用6S)スイフトで
import AudioToolbox
private let isDevice = TARGET_OS_SIMULATOR == 0
func vibrate() {
if isDevice {
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
}
}
iOS 10の追加のハプティッククラス:[UIImpactFeedbackGenerator](https://developer.apple.com/documentation/uikit/uiimpactfeedbackgenerator)と[UISelectionFeedbackGenerator](https://developer.apple.com/documentation/uikit/uiselectionfeedbackgenerator) – bendytree
@bendytree新しいサブクラスを追加していただき、ありがとうございます。私はいつもここで古い投稿を見ているわけではありません:) –
例
import AudioToolbox
AudioServicesPlaySystemSound(1519) // Actuate `Peek` feedback (weak boom)
AudioServicesPlaySystemSound(1520) // Actuate `Pop` feedback (strong boom)
AudioServicesPlaySystemSound(1521) // Actuate `Nope` feedback (series of three weak booms)
念に - iPhone 7/7+ためhere're例。
func is3dTouchAvailable(traitCollection: UITraitCollection) -> Bool {
return traitCollection.forceTouchCapability == UIForceTouchCapability.available
}
、その後、タッチイベントでは、それは
func touchMoved(touch: UITouch, toPoint pos: CGPoint) {
let location = touch.location(in: self)
let node = self.atPoint(location)
//...
if is3dTouchEnabled {
bubble.setPressure(pressurePercent: touch.force/touch.maximumPossibleForce)
} else {
// ...
}
}
touch.forceとして利用できるようになります。ここに私のブログがあります:あなたはそれが最初に利用できるかどうかを検出する必要がある -
力touch用としてコードサンプルを使用したより詳細な例を示します。
http://www.mikitamanko.com/blog/2017/02/01/swift-how-to-use-3d-touch-introduction/
1519-1521コードはここでもう適用されないようです。あなたは問題にぶつかり合ったのですか? @Mikita Manko –
さまざまなフィードバックタイプがあります。それぞれを試して、あなたのニーズに合ったものを見つけてください:
// 1, 2, 3
let generator = UINotificationFeedbackGenerator()
generator.notificationOccurred(.error)
generator.notificationOccurred(.success)
generator.notificationOccurred(.warning)
// 4
let generator = UIImpactFeedbackGenerator(style: .light)
generator.impactOccurred()
// 5
let generator = UIImpactFeedbackGenerator(style: .medium)
generator.impactOccurred()
// 6
let generator = UIImpactFeedbackGenerator(style: .heavy)
generator.impactOccurred()
// 7
let generator = UISelectionFeedbackGenerator()
generator.selectionChanged()
- 1. Qt触覚フィードバックon android
- 2. iPhone 6Sを手動でピークとポップのように振動させますか?
- 3. Androidでの触覚フィードバックの一般設定
- 4. ImageViewが動作していないときに触覚フィードバックを行う方法
- 5. Androidでxmlの触覚フィードバックを定義する方法はありますか?
- 6. iPhone 6sのフォントサイズ+
- 7. 画面に触れた後の振動
- 8. iPhone 6SおよびiPhone 6S Plusのプラットフォーム文字列は何ですか?
- 9. アプリケーションは、私は、iOS 9とXcode 7のリリースで導入された新機能を考えると、IOS 9を実行している6S私のiPhone上のアプリのテストを実行していますIOS 9
- 10. iOSの9のエンタープライズアプリは
- 11. Swift 2.0 PopoverビューでiPhone 6sの適切な位置を取得できませんが、iPhone 6sでうまく動作します
- 12. 特定の場所に触れるときに触覚フィードバックを取得するにはどうすればよいですか?
- 13. iOSの9 supportedInterfaceOrientationsは
- 14. iOS 9 - NSAllowsArbitraryLoads scope
- 15. UILocalNotification音と振動の設定IOS
- 16. iOS 9のsegueForUnwindingToViewController
- 17. 9/iOSの9.0.1
- 18. UIAlertControllerがiOS 9で動作しない
- 19. iPhoneをサイレントモードで振動させることはできますか?
- 20. ストリーミング中のiPhone 6Sのオーディオに関する問題
- 21. チェックiOSの9
- 22. 奇妙な9パッチの振る舞い
- 23. iOS 9 Black Launch Screen
- 24. のiOS 4.2.1リリースモードで視覚的なバグではなく、デバッグモードまたはiOS 5
- 25. IOS 9エラードメイン= kCLErrorDomainコード= 0 "(null)"
- 26. 動的にロードされたブートストラップモーダルがiOS 9でスクロールしない
- 27. iOS振動ユニットのきめ細かな制御
- 28. ios 8 UILocalサイレントモードでの振動の変化
- 29. MapKit iOS 9 detailCalloutAccessoryView usage
- 30. iPhoneプッシュ通知カスタムサウンド、いいえサイレントモードで振動しますか?
プライベートAPIが動作しません。 – mayqiyue