2015-04-07 48 views
0

我已经做了UIImagePicker添加视图上的UIViewController

UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 
    picker.delegate = self; 
    picker.allowsEditing = YES; 
    picker.sourceType = UIImagePickerControllerSourceTypeCamera; 
    picker.cameraDevice = UIImagePickerControllerCameraDeviceFront; 
    picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil]; 

而且我想添加一个半圈,以让我做到这一点,

CGContextRef gc = UIGraphicsGetCurrentContext(); 
    CGContextBeginPath(gc); 
    CGContextAddArc(gc, 100, 100, 50, -M_PI_2, M_PI_2, 1); 
    CGContextClosePath(gc); // could be omitted 
    CGContextSetFillColorWithColor(gc, [UIColor cyanColor].CGColor); 
    CGContextFillPath(gc); 
    UIView *someView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 400, 400)]; 
    [someView.layer renderInContext:gc]; 
    [picker setCameraOverlayView:someView]; 

但后来当我告诉像这样的选择器

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

我没有看到半圆?这是为什么发生?

谢谢

回答

1

嘿,你没有正确的方式。

执行下面的步骤,将帮助你......

见下答案.. https://stackoverflow.com/questions/5552210/uitableviewcells-invalid-context-trying-to-draw

CircleView.h

#import <UIKit/UIKit.h> 

@interface CircleView : UIView 

@end 

CircleView.m

#import "CircleView.h" 

@implementation CircleView 

- (void)drawRect:(CGRect)rect 
    { 
    CGContextRef gc = UIGraphicsGetCurrentContext(); 
    CGContextBeginPath(gc); 
    CGContextAddArc(gc, 100, 100, 50, -M_PI_2, M_PI_2, 1); 
    CGContextClosePath(gc); // could be omitted 
    CGContextSetFillColorWithColor(gc, [UIColor cyanColor].CGColor); 
    CGContextFillPath(gc); 
} 
@end 

在imagepicker加入半圆Implimenttion在这里

UIImagePickerController *controller = [[UIImagePickerController alloc]init]; 
controller.delegate=self; 
controller.sourceType = UIImagePickerControllerSourceTypeCamera; 
[self presentViewController:controller animated:YES completion:^{ 
      CircleView *someView = [[CircleView alloc] initWithFrame:CGRectMake(0, 0, 400, 400)]; 
      [someView setBackgroundColor:[UIColor colorWithWhite:0.5 alpha:0.5]]; 
      [controller setCameraOverlayView:someView]; 
     }]; 
+0

的链接断开 – iqueqiorio

+0

遗憾。现在检查.. –

+0

好吧谢谢,我只是有点困惑什么DrawCircleView是什么? – iqueqiorio

相关问题