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 回答