菜鸟教程小白 发表于 2022-12-13 15:45:16

ios - 选择视频时是否可以更改 `UIImagePickerController` 的标题?


                                            <p><p>我有开放的照片库来选择视频。这是我的代码:</p>

<p></p>

<pre><code>- (void)selectMediaFrom:(UIImagePickerControllerSourceType)sourceType {
   UIImagePickerController *imagePicker = [ init];
    imagePicker.sourceType = sourceType;
    imagePicker.delegate = self;
    //imagePicker.allowsEditing = YES;

    if (selectedMediaType == MediaVideos) {
      imagePicker.mediaTypes = @[(NSString *)kUTTypeMovie, (NSString *)kUTTypeVideo];
      if (sourceType == UIImagePickerControllerSourceTypeCamera) {
            imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
      }
    }
    else if (selectedMediaType == MediaPhotos) {
      imagePicker.mediaTypes = @[(NSString *)kUTTypeImage];
      if (sourceType == UIImagePickerControllerSourceTypeCamera) {
            imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
      }
    }

    if (IS_IPHONE) {
      ;
    }
    else {
      dispatch_async(dispatch_get_main_queue(), ^{

            ;
            ;
      });
    }
}
</code></pre>

<p>它总是将 <code>UIImagePickerController</code> 的标题显示为 <strong>Photos</strong>,请参见我附上的截图。</p>

<p> <a href="/image/rqcgu.png" rel="noreferrer noopener nofollow"><img src="/image/rqcgu.png" alt="imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary and imagePicker.mediaTypes = @[(NSString *)kUTTypeMovie, (NSString *)kUTTypeVideo]"/></a> </p>

<p>但是,我打开 <strong>iPhone</strong> 默认 <strong>照片应用程序</strong> 并检查,显示视频文件夹:见下文</p>

<p> <a href="/image/5D5cp.png" rel="noreferrer noopener nofollow"><img src="/image/5D5cp.png" alt="Default Photos App"/></a> </p>

<p>那为什么它不显示 <strong>Videos</strong> 标题?我们可以改变它吗?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>是的,您可以更改所需的导航标题。</p>

<p>添加<code>UINavigationControllerDelegate</code></p>的委托(delegate)

<p><strong>Swift 3.0</strong></p>

<pre><code>func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool){
    viewController.navigationItem.title = &#34;Kirit Modi&#34;
}
</code></pre>

<p><strong> Objective-C </strong> </p>

<pre><code>- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
    ;
}
</code></pre>

<p><strong>查看输出:</strong> </p>

<p> <a href="/image/QA8Qc.png" rel="noreferrer noopener nofollow"><img src="/image/QA8Qc.png" alt="enter image description here"/></a> </p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 选择视频时是否可以更改`UIImagePickerController` 的标题?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/46599848/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/46599848/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 选择视频时是否可以更改 `UIImagePickerController` 的标题?