Skip to content

Commit

Permalink
Added draggable option
Browse files Browse the repository at this point in the history
  • Loading branch information
ijason committed Mar 10, 2013
1 parent 82f4c94 commit e69c962
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
5 changes: 4 additions & 1 deletion FaceCamViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 17 additions & 3 deletions FaceCamViewer.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

@implementation FaceCamViewer

@synthesize cameraType, session;
@synthesize cameraType, session, draggable;

- (id)initWithFrame:(CGRect)frame
{
Expand Down Expand Up @@ -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 {
Expand All @@ -82,7 +82,6 @@ -(void)startFaceCam {
if (!session) {
session = [[AVCaptureSession alloc] init];
}
//AVCaptureSession *session = [[AVCaptureSession alloc] init];
session.sessionPreset = AVCaptureSessionPresetMedium;

NSError *error = nil;
Expand Down Expand Up @@ -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

0 comments on commit e69c962

Please sign in to comment.