2012-02-25 6 views
0

私は、プログラムによっていくつかのボタンを含むビューを持つUIViewControllerサブクラスを作成し、それをUINavigationControllerに追加しようとしています。私がそうするとき、あなたはそれを引き起こすために各ボタンの上約40または50ポイントを触れなければなりません(ボタンに触れることは何もしません)。ボタンとあなたが触れなければならない実際の領域の間の距離は、UINavigationControllerのナビゲーションバーの高さと同じであると思われます。どのようにこれを修正するための任意の提案?ここでは、ウィンドウとボタンを作成するコードは(私のUIViewControllerサブクラスから)です:UINavigationController内のUIButtonが間違った場所からタップを受け取ります

- (void)loadView 
{ 
    ... 

    UIWindow* mainView = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]; 
    [mainView setBackgroundColor:[UIColor groupTableViewBackgroundColor]]; 
    [mainView makeKeyAndVisible]; 

    [self setView:mainView]; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    UIButton* encryptButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    [encryptButton setTitle:@"Encrypt" forState:UIControlStateNormal]; 
    [encryptButton setFrame:CGRectMake(([[self view] bounds].size.width - 150.0f)/2.0f, 
              ([[self view] bounds].size.height - 120.0f)/2.0f, 150.0f, 40.0f)]; 
    [encryptButton setBounds:CGRectMake(0.0f, 0.0f, 150.0f, 40.0f)]; 
    [encryptButton addTarget:self action:@selector(encryptPressed:) forControlEvents:UIControlEventTouchUpInside]; 
    [[self view] addSubview:encryptButton]; 
    [encryptButton release]; 

    UIButton* decryptButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    [decryptButton setTitle:@"Decrypt" forState:UIControlStateNormal]; 
    [decryptButton setFrame:CGRectMake(([[self view] bounds].size.width - 150.0f)/2.0f, 
              ([[self view] bounds].size.height - 120.0f)/2.0f + 80.0f, 150.0f, 40.0f)]; 
    [decryptButton addTarget:self action:@selector(decryptPressed:) forControlEvents:UIControlEventTouchUpInside]; 
    [[self view] addSubview:decryptButton]; 
    [decryptButton release]; 
} 

ここでUINavigationControllerをセットアップするコードは次のとおりです。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 

    UUMainWindowViewController* mainWinController = [[UUMainWindowViewController alloc] init]; 

    UINavigationController* mainNavController = [[UINavigationController alloc] 
                initWithRootViewController:mainWinController]; 
    [mainNavController navigationBar].barStyle = UIBarStyleBlack; 
    [self.window setRootViewController:mainNavController]; 

    [self.window makeKeyAndVisible]; 
    return YES; 
} 

答えて

0

は私自身の答えを考え出しました。 UIViewControllerでUIWindowを構築していた初心者の間違いでしたが、実際には代わりにUIViewを作成する必要があるだけです。どうやらUIWindowが1つしかないはずなので、おそらくUIWindowは画面全体の不動産を自分自身に持っていると仮定していたため、これはうまくいかなかったようです。

関連する問題