1

次のコードを指定すると、ボタンはツールバーに表示されません。何か問題がありますか?

UIImagePickerController* cameraPickerController = [[UIImagePickerController alloc] init];
cameraPickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraPickerController.delegate =self;
cameraPickerController.showsCameraControls = NO;
cameraPickerController.toolbarHidden = NO;

UIBarButtonItem *cancelBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target: self action: @selector(cancel)];
UIBarButtonItem *flexibleBarSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
flexibleBarSpace.width = 1000;
UIBarButtonItem *cameraBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:cameraPickerController action:@selector(takePicture)];
UIBarButtonItem *faceBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"Show facemask" style:UIBarButtonItemStyleBordered target: self action: @selector(showFacemask)];
cameraPickerController.toolbar.items = [NSArray arrayWithObjects:cancelBarButtonItem,flexibleBarSpace,cameraBarButtonItem,flexibleBarSpace,faceBarButtonItem,nil];

[self presentModalViewController:cameraPickerController animated:YES];

これらのcancelBarButtonsおよびその他は、理論的にはツールバーに表示されます。ただし、この場合はそうではありません。お知らせ下さい。

4

3 に答える 3

3

(私が思うに)まだ表示されていないため、ツールバーに項目を追加することはできませんUIImagePickerController。代わりに、次のことを試してください。

UIImagePickerController* cameraPickerController = [[UIImagePickerController alloc] init];
cameraPickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraPickerController.delegate =self;
cameraPickerController.showsCameraControls = NO;

UIToolbar *theToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 436, 320, 44)];

UIBarButtonItem *cancelBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target: self action: @selector(cancel)];
UIBarButtonItem *flexibleBarSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
flexibleBarSpace.width = 1000;
UIBarButtonItem *cameraBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:cameraPickerController action:@selector(takePicture)];
UIBarButtonItem *faceBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"Show facemask" style:UIBarButtonItemStyleBordered target: self action: @selector(showFacemask)];

theToolbar.items = [NSArray arrayWithObjects:cancelBarButtonItem, flexibleBarSpace, cameraBarButtonItem, faceBarButtonItem, nil];

[cameraPickerController setCameraOverlayView:theToolbar];

[self presentModalViewController:cameraPickerController animated:YES];

基本的に、新しいツールバーを作成して、として設定しましたcameraOverlayView

乾杯!

于 2012-07-24T20:37:50.933 に答える
3

この投稿を検索して見つけた人のための遅い回答。

presentViewController:animated:completioniOS 5以降では、解決策は、完了ブロックのツールバー項目を呼び出して設定することです。

    UIImagePickerController* cameraPickerController = [[UIImagePickerController alloc] init];
    cameraPickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
    cameraPickerController.delegate =self;
    cameraPickerController.showsCameraControls = NO;
    cameraPickerController.toolbarHidden = NO;

    UIBarButtonItem *cancelBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target: self action: @selector(cancel)];
    UIBarButtonItem *flexibleBarSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    flexibleBarSpace.width = 1000;
    UIBarButtonItem *cameraBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:cameraPickerController action:@selector(takePicture)];
    UIBarButtonItem *faceBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"Show facemask" style:UIBarButtonItemStyleBordered target: self action: @selector(showFacemask)];

    //cameraPickerController.toolbar.items = [NSArray arrayWithObjects:cancelBarButtonItem,flexibleBarSpace,cameraBarButtonItem,flexibleBarSpace,faceBarButtonItem,nil];
    NSArray *tbItems = [NSArray arrayWithObjects:cancelBarButtonItem,flexibleBarSpace,cameraBarButtonItem,flexibleBarSpace,faceBarButtonItem,nil];

    // [self presentModalViewController:cameraPickerController animated:YES];
    cameraPickerController.modalTransitionStyle = UIModalPresentationFullScreen;
    [self presentViewController:picker animated:YES completion:^{
        cameraPickerController.toolbar.items = tbItems;
    }];
于 2013-05-10T14:31:59.467 に答える
0

だから私は同様の問題を検索し、これを見つけまし

しかし基本的に彼の問題は彼が試みていたということでした

[self presentModalViewController:foo animated:YES];

修正は

[self.tabBarController presentModalViewController:camera animated:YES];

これで問題が解決するかどうかも確認してください。より多くのコードを見ずに確実に言うのは難しい

于 2012-07-24T19:00:51.053 に答える