2015-04-07 81 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

相關問題