uikit - iOS7 UIPickerView 无法正确显示带有图像的自定义 View

标签 uikit ios7 uipickerview

这个问题开始在 iOS7 中使用新的 UIPickerView Controller 发生。要在 UIPickerView Controller 中使用图像,您必须使用委托(delegate)方法返回图像:

pickerView:viewForRow:forComponent:reusingView:

问题是屏幕随后会出现各种奇怪的行为 - 当您在控件上下移动手指时, ImageView 会消失。

最佳答案

这是从 iOS 7.0.2 开始在开发论坛上发布的解决方案:

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
    // self.myImages is an array of UIImageView objects
    UIView * myView = [self.myImages objectAtIndex:row];

    // first convert to a UIImage
    UIGraphicsBeginImageContextWithOptions(myView.bounds.size, NO, 0);

    [myView.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage * image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    // then convert back to a UIImageView and return it
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

    return imageView;
}

关于uikit - iOS7 UIPickerView 无法正确显示带有图像的自定义 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19158319/

相关文章:

ios - 为 iOS 7 半透明 UINavigationBar 实现明亮、生动的色彩

ios - UIImagePickerController 后退按钮/取消按钮不可见

ios - 使用 CGPattern 填充 MKPolygon 时,多边形叠加相互干扰(使用 Quartz 2D)

ios - Google Analytics SDK 在 Xcode 6.3 中产生问题

ios - 如何多次使用 UIPickerView 和 TextField ?

ios - 我们如何在选择段后调用 PickView 的 didSelectRow?

iphone - 如何制作 UIBarButtonItem 动画翻转?

swift - 按下 UIButton 时带参数的触发函数

ios - presentViewController 不存在

objective-c - iOS didSelectRow 没有在连续选择时调用?