在cameraOverlayView中绘制图像

时间:2014-06-28 00:46:58

标签: ios objective-c

我使用此代码创建了一个带有自定义cameraOverlayView的UIImagePickerController。出于测试目的,叠加层应该是我使用UIBezierPath在CircleView中绘制的圆。但是,CircleView中绘制的圆不会出现在叠加层中。叠加层应该是我的CircleView所在的UIView的子类。你可以解释为什么当重叠弹出时圆圈没有出现?我在viewDidLoad中初始化了circleView,然后将其设置为cameraOverlayView中的viewDidAppear

的viewController

@property (strong, nonatomic) CircleView *overlay;

viewDidLoad中

self.overlay = [[CircleView alloc] init];

viewDidAppear

    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

        UIImagePickerController *picker = [[UIImagePickerController alloc] init];

        picker.delegate = self;
        picker.allowsEditing = YES;
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
        picker.showsCameraControls = NO;
        picker.navigationBarHidden = YES;
        picker.wantsFullScreenLayout = YES;
        picker.cameraOverlayView = self.overlay;
        picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];

        [self presentViewController:picker animated:YES completion:NULL];
    }

CircleView

- (id)initWithCoder:(NSCoder *)aDecoder {

    if (self = [super initWithCoder:aDecoder]) {

        self.shape = [UIBezierPath bezierPathWithOvalInRect:(CGRectMake(0, 50, 50, 50))];


    }
    return self;
}


- (void)drawRect:(CGRect)rect{

  [[UIColor colorWithRed: (114/255.0) green: (5/255.0) blue:(46/255.0) alpha:1] setFill];
   [self.shape fill];


}

1 个答案:

答案 0 :(得分:1)

这里有两个问题:

  • 您的圈子覆盖视图尺寸为零,因为您使用init代替initWithFrame:创建了它(init会回到{0,0,0,0}的框架上,因为你没有提供任何框架信息。)

  • 您的圈子覆盖视图在initWithCoder:中执行了一些重要的初始化,但是从不调用此方法,因为您使用init实例化它。因此,self.shape的{​​{1}}为零,drawRect:中没有任何内容。