2014-01-20 12 views
5

カスタムキーボードで問題が発生し、「クリック」音が鳴ります。私は次のクラスと定義を使用しています。UIInputViewAudioFeedbackプロトコルの問題(enableInputClicksWhenVisibleが呼び出されない)

KeyboardShotInputView.h

#import <UIKit/UIKit.h> 

//------------------------------------------------------------------------------ 
// Protocol defintion 
//------------------------------------------------------------------------------ 

@protocol KeyboardShotInputDelegate 

- (void)shotButtonDidTouchDown:(NSString*)value; 
- (void)deleteButtonDidTouchDown; 

@end 

//------------------------------------------------------------------------------ 
// Interface defintition 
//------------------------------------------------------------------------------ 

@interface KeyboardShotInputView : UIView <UIInputViewAudioFeedback> 

@property (nonatomic, strong) id <KeyboardShotInputDelegate> delegate; 
@property (strong, nonatomic) IBOutlet UIView *keyboard; 
@property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *shotButtonCollection; 
@property (weak, nonatomic) IBOutlet UIButton *deleteButton; 

- (UIView *) getKeyboardView; 
- (IBAction)shotButtonPressed:(id)sender; 
- (IBAction)deleteButtonPressed:(id)sender; 
@end 

KeyboardShotInputView.m

#import "KeyboardShotInputView.h" 

@implementation KeyboardShotInputView 

@synthesize keyboard; 
@synthesize shotButtonCollection; 
@synthesize deleteButton; 

//------------------------------------------------------------------------------ 

- (id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 

    if (self) { 
     [self loadInputView]; 
    }   
    return self; 
} 

//------------------------------------------------------------------------------ 

- (id)initWithCoder:(NSCoder *)coder 
{ 
    self = [super initWithCoder:coder]; 

    if (self) { 
     [self loadInputView]; 
    } 
    return self; 
} 

//------------------------------------------------------------------------------ 

- (void)loadInputView 
{ 
    // load nib file 
    UINib *inputViewNib = [UINib nibWithNibName:@"KeyboardShotInput" bundle:nil]; 
    [inputViewNib instantiateWithOwner:self options:nil]; 

    // layout shot input buttons 
    for (UIButton *btn in shotButtonCollection) { 
     //[btn.layer setBorderWidth:1.0]; 
     [btn.layer setCornerRadius:5.0]; 
     [btn.layer setShadowColor:[UIColor blackColor].CGColor]; 
     [btn.layer setShadowOpacity:0.9]; 
     [btn.layer setShadowRadius:1.0]; 
     [btn.layer setShadowOffset:CGSizeMake(0.0, 1.0)]; 
    } 

    // layout delete button 
    [self.deleteButton.layer setBorderWidth:1.0]; 
    [self.deleteButton.layer setCornerRadius:5.0]; 
    [self.deleteButton.layer setCornerRadius:5.0]; 
    [self.deleteButton.layer setShadowColor:[UIColor blackColor].CGColor]; 
    [self.deleteButton.layer setShadowOpacity:0.9]; 
    [self.deleteButton.layer setShadowRadius:1.0]; 
    [self.deleteButton.layer setShadowOffset:CGSizeMake(0.0, 1.0)]; 
} 

//------------------------------------------------------------------------------ 

/** 
* Enable input clicks. 
*/ 
- (BOOL) enableInputClicksWhenVisible 
{ 
    NSLog(@"enableInputClicksWhenVisible: YES"); 
    return YES; 
} 

//------------------------------------------------------------------------------ 

/** 
* Return Keyboard object. 
* 
* @return UIView of the keyboard. 
*/ 
- (UIView *) getKeyboardView; 
{ 
    return self.keyboard; 
} 

//------------------------------------------------------------------------------ 

/** 
* Any of the shot button is pressed. 
* 
* @param sender Shot button object. 
*/ 
- (IBAction)shotButtonPressed:(id)sender 
{ 
    if (!self.delegate) return; 

    // play click 
    NSLog(@"shotButtonPressed: playInputClick"); 
    [[UIDevice currentDevice] playInputClick]; 

    [self.delegate shotButtonDidTouchDown:[(UIButton *)sender currentTitle]]; 
} 

//------------------------------------------------------------------------------ 

/** 
* The delete button is pressed. 
* 
* @param sender DEL button object. 
*/ 
- (IBAction)deleteButtonPressed:(id)sender 
{ 
    if (!self.delegate) return; 

    // play click 
    NSLog(@"deleteButtonPressed: playInputClick"); 
    [[UIDevice currentDevice] playInputClick]; 
    [self.delegate deleteButtonDidTouchDown]; 
} 

@end 

EditShootingResultTableViewController.m

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    // connect keyboard toolbar 
    self.keyboardToolbar = [[KeyboardToolbar alloc] init]; 
    self.keyboardToolbar.delegate = self; 

    // connect shot input keyboard  
    self.keyboardShotInputView = [[KeyboardShotInputView alloc] init]; 
    self.keyboardShotInputView.delegate = self; 

    for (UITextField* tf in self.tfShotCollection) { 
     tf.inputView = [self.keyboardShotInputView getKeyboardView]; 
    } 

    //... 
} 

//------------------------------------------------------------------------------ 
// @name KeyboardShotInputDelegates 

/** 
* Receive a message every time the user touches any shot input button. 
*/ 
- (void)shotButtonDidTouchDown:(NSString *)value 
{ 
    // handle keyboard event here... 
} 

//------------------------------------------------------------------------------ 

/** 
* Receive a message every time the user touches the shot delete button. 
*/ 
- (void)deleteButtonDidTouchDown 
{ 
    // handle keyboard event here... 
} 

すべてうまくいきます。キーボードの呼び出しでさえも代理人。私はenableInputClicksWhenVisibleメソッドからNSLogを除くすべてのNSLog出力を取得します。誰が何がうまくいかないか知っていますか私は2,3日後に解決策を見つけることができませんでした。 :-(

よろしく

+0

アイデアはありますか? – Morpheus78

+0

あなたはこれに対する解決策を見つけましたか?鉱山はあまりにも動作していません – tnylee

答えて

5

はこれを試してみてください:Appleの実装にバグがあるよう

AudioServicesPlaySystemSound(0x450); 
+2

ソリューションは正常に動作します。しかし、次の行が機能しない理由がありますか? [[UIDevice currentDevice] playInputClick]; – Morpheus78

0

に思える; UIViewのサブクラスを認識できるかどうかについて、いくつかの隠されたルールがあるように見えますUIInputViewAudioFeedbackプロトコルを実装として

しかし、このブログの記事は、あなたが試すことができ、作業のサンプルを持っています。

http://gregheo.com/blog/ios-custom-keyboard/

私自身の試みでは、カスタムキーパッドコントロールを使ってxibにサブビューを定義しました。うまく行かなかった。しかし、ブログ記事で参照されているサンプルコードでは、xibのルートビューでキーパッドコントロールを定義しています。何らかの理由でこれが機能します。

+0

iOS8上では動作しません:/ – Bersaelor

関連する問題