【问题标题】:Hiding button until picture is selected隐藏按钮直到选择图片
【发布时间】:2014-09-03 23:30:27
【问题描述】:

我有一个应用程序,允许用户从相机胶卷中选择一张照片,或者拍摄一张新照片,然后替换占位符图像。

我想创建一个按钮,当点击它时会清除图像(因为它现在的状态,一旦你拍照或从库中选择一个,你只能替换它,但你不能完全删除它)

我希望删除图片按钮仅显示已拍摄或选择的图片。我知道这是可能的,因为我已经看到其他一些 Apple 应用程序这样做了,但我不知道该怎么做,我已经在 google 和 stackoverflow 上搜索了解决方案,但没有找到任何符合此描述的内容。

任何帮助将不胜感激!

【问题讨论】:

    标签: ios uibutton uiimage uiimagepickercontroller


    【解决方案1】:

    为此,您需要实现 UIImagePickerControllerDelegate 的imagePickerController:didFinishPickingMediaWithInfo: 方法。当 UIImagePickerController 完成选择媒体时调用该方法。大致是这样的:

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
        // Dismiss the uiimagepicker
        [picker dismissViewControllerAnimated:YES completion:nil];
    
        // Get the image that is selected  
        UIImage *imageSelected = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    
        // Set the image to the place holder
        [self.placeholder setImage:imageSelected];
    
        // Hide the button
        self.imageSelectButton.hidden = YES;
    }
    

    请务必查看处理取消事件等的其他委托方法。

    【讨论】:

    • 请注意,在示例中,我假设您将占位符 UIImage 命名为 self.placeholder,而您要隐藏的按钮命名为 self.imageSelectButton。用实际名称替换它们。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-21
    • 1970-01-01
    • 1970-01-01
    • 2015-02-10
    • 2012-08-06
    • 2013-03-04
    相关资源
    最近更新 更多