diff --git a/FaceCamViewer.h b/FaceCamViewer.h index f26bb7f..d97eb27 100644 --- a/FaceCamViewer.h +++ b/FaceCamViewer.h @@ -35,10 +35,13 @@ typedef enum{ IPAD = 2 } DeviceType; -@interface FaceCamViewer : UIView +@interface FaceCamViewer : UIView { + CGPoint offset; +} @property (nonatomic, assign) AVCaptureDevicePosition cameraType; @property (nonatomic, strong) AVCaptureSession *session; +@property (nonatomic, assign) BOOL draggable; -(id)initWithDeviceType:(DeviceType)type; -(void)startFaceCam; diff --git a/FaceCamViewer.m b/FaceCamViewer.m index 61aaa53..666db59 100644 --- a/FaceCamViewer.m +++ b/FaceCamViewer.m @@ -30,7 +30,7 @@ @implementation FaceCamViewer -@synthesize cameraType, session; +@synthesize cameraType, session, draggable; - (id)initWithFrame:(CGRect)frame { @@ -71,8 +71,8 @@ -(void)setDefaults { [self setBackgroundColor:[UIColor blackColor]]; self.layer.cornerRadius = 5; self.layer.masksToBounds = YES; - self.cameraType = AVCaptureDevicePositionFront; + self.draggable = NO; } -(void)startFaceCam { @@ -82,7 +82,6 @@ -(void)startFaceCam { if (!session) { session = [[AVCaptureSession alloc] init]; } - //AVCaptureSession *session = [[AVCaptureSession alloc] init]; session.sessionPreset = AVCaptureSessionPresetMedium; NSError *error = nil; @@ -132,4 +131,19 @@ -(AVCaptureDevice *)CameraIfAvailable return captureDevice; } +-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ + UITouch *aTouch = [touches anyObject]; + offset = [aTouch locationInView: self]; +} + +- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { + if (self.draggable) { + UITouch *touch = [touches anyObject]; + CGPoint location = [touch locationInView:self.superview]; + [UIView beginAnimations:@"Dragging" context:nil]; + self.frame = CGRectMake(location.x-offset.x, location.y-offset.y, self.frame.size.width, self.frame.size.height); + [UIView commitAnimations]; + } +} + @end