0

私のカメラオーバーレイ画面のほとんどは、不透明なオーバーレイで覆われています。残りの部分については、いくつかのボタンを追加したいと思いUIToolbarます。これらのボタンをプログラムでクリック可能にする方法についても言及してください。

完全に表示されるオーバーレイを追加した方法は次のとおりです。

- (UIView*)CommomOverlay  {
    //Both of the 428 values stretch the overlay bottom to top for overlay function. It doesn't cover it. 
    UIView* view = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,428)];
    UIImageView *FrameImg = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,428)];
    [FrameImg setImage:[UIImage imageNamed:@"newGraphicOverlay.png"]];
    [view addSubview:FrameImg];
    return view; 
}

同様に、作業ツールバー(クリック可能で、2つのボタンで完全に機能可能)を追加するにはどうすればよいですか?

4

2 に答える 2

2

これを試してください:(viewDidLoadまたはviewWillAppearで)

//create toolbar and set origin and dimensions
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 428, 320, 32)];

//create buttons and set their corresponding selectors
UIBarButtonItem *button1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(button1Tap:)];
UIBarButtonItem *button2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRewind target:self action:@selector(button2Tap:)];

//if you want custom icons, use something like this:
UIBarButtonItem *button3 = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon1_portrait.png"] landscapeImagePhone:[UIImage imageNamed:@"icon1_landscape.png"] style:UIBarButtonItemStylePlain target:self action:@selector(button3Tap:)];

//add buttons to the toolbar
[toolbar setItems:[NSArray arrayWithObjects:button1, button2, nil]];

//add toolbar to the main view
[self.view addSubview:toolbar];
  • 次のようなセレクターを作成します。

    -(void)button1Tap:(id)sender {
        NSLog(@"Button 1 was tapped!");
        // do whatever needs to happen
    }
    
于 2012-07-21T07:43:12.683 に答える
0

私があなたを正しく理解しているなら、あなたがしなければならないのはUIToolBar関数にを追加することだけです:

- (UIView*)CommomOverlay  {
    //Both of the 428 values stretch the overlay bottom to top for overlay function. It doesn't cover it.
    UIView* view = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,428)];
    UIImageView *FrameImg = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,428)];
    [FrameImg setImage:[UIImage imageNamed:@"newGraphicOverlay.png"]];
    UIToolbar *myToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
    UIBarButtonItem *myBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(myFunction)];
    [myToolBar setItems:[NSArray arrayWithObjects:myBarButtonItem, nil] animated:YES];
    [FrameImg addSubview:myToolBar];
    [view addSubview:FrameImg];
    return view;
}
于 2012-07-21T10:22:37.367 に答える