2

iOS6 ユニバーサル アプリで UITextField の inputAccessoryView として透明な UIToolbar を使用しようとしています。

iOS6 iPhone で実行すると、ツールバーは透明に見えますが、上部の境界線が表示されます。そして、これは iOS6 iphone でのみ発生します。iOS6 ipad デバイスではなく、iOS6 iPad シミュレーターでも、iOS6 iPhone シミュレーターでもありません。デバイスとシミュレーターのスクリーンショットは次のとおりです...

iOS6 デバイスのスクリーンショット

iOS6 シミュレーターのスクリーンショット

これが私のコードです...

// Transparent Toolbar.m

@implementation TransparentToolbar
- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    [[UIColor clearColor] setFill];
    CGContextFillRect(context, self.bounds);
}
@end

// ViewController.m

#import "ViewController.h"
#import "TransparentToolbar.h"

@interface ViewController () {
    TransparentToolbar *_accessoryView;
}
@end

@implementation ViewController
@synthesize textField;
- (TransparentToolbar *)_accessoryView
{
    if (!_accessoryView) {
        _accessoryView = [[TransparentToolbar alloc] init];
        [_accessoryView sizeToFit];
        [_accessoryView setTranslucent:YES];

        UIBarButtonItem *flexButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];

        UIButton *resignKeyboardButton = [UIButton buttonWithType:UIButtonTypeInfoDark];
        [resignKeyboardButton setFrame:CGRectMake(0, 0, 44, 44)];
        [resignKeyboardButton setTitle:@"DONE" forState:UIControlStateNormal];
        [resignKeyboardButton addTarget:self action:@selector(didTapResignKeyboardButton:) forControlEvents:UIControlEventTouchUpInside];

        UIBarButtonItem *resignKeyboardBarButton =[[UIBarButtonItem alloc] initWithCustomView:resignKeyboardButton];

        NSArray *itemsArray = [NSArray arrayWithObjects:flexButton, resignKeyboardBarButton, nil];
        [_accessoryView setItems:itemsArray];
    }

    return _accessoryView;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [textField setInputAccessoryView:[self _accessoryView]];
}

- (void)didTapResignKeyboardButton:(UIBarButtonItem *)aButtonItem
{
    [textField resignFirstResponder];
}
@end

ここで何がうまくいかないのでしょうか?

4

0 に答える 0