UINotificationFeedbackGenerator类型错误[ObjC]

时间:2018-09-10 08:03:05

标签: ios objective-c

我在网上搜索了UIFeedbackGenerators,但仅发现有关UIImpactFeedbackGenerators的信息。但以我为例,我希望某个APP在例如登录失败时执行特定的触觉反馈。所以我试图创建一个UINotificationFeedbackTypeError。我不知道如何将生成器设置为Type Error

@interface ViewController ()

@property (nonatomic, strong) UIImpactFeedbackGenerator *impactFeedbackGenerator;
@property (nonatomic, strong) UINotificationFeedbackGenerator *generator;
@property (strong, nonatomic) IBOutlet UIButton *button;
@property (strong, nonatomic) IBOutlet UIButton *button2;
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.button addTarget:self action:@selector(didPressButton:) forControlEvents:UIControlEventTouchUpInside];

    // Choose between heavy, medium, and light for style
    self.impactFeedbackGenerator = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleMedium];

    // Primes feedback generator for upcoming events and reduces latency
    [self.impactFeedbackGenerator prepare];




    [self.button2 addTarget:self action:@selector(didPressButton2:)  forControlEvents:UIControlEventTouchUpInside];

    self.generator = [[UINotificationFeedbackGenerator alloc] init];

    [self.generator prepare];

}

- (void)didPressButton:(UIButton *)sender
{
    // Triggers haptic
    [self.impactFeedbackGenerator impactOccurred];
    NSLog(@"Button Pressed");
}

- (void)didPressButton2:(UIButton *)sender
{
    // Triggers haptic
    [self.generator impactOccurred];
    NSLog(@"Button Pressed");
}


@end

0 个答案:

没有答案