Skip to content

Commit

Permalink
Added draggable option
Browse files Browse the repository at this point in the history
Setting draggable will allow the view to be dragged on touch
  • Loading branch information
ijason committed Mar 10, 2013
1 parent c443c3a commit 82f4c94
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
Binary file not shown.
5 changes: 4 additions & 1 deletion FaceCamTest/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 FaceCamTest/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
7 changes: 4 additions & 3 deletions FaceCamTest/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ - (void)viewDidLoad
AVCaptureSession *session = [[AVCaptureSession alloc] init];
FaceCamViewer *viewer3 = [[FaceCamViewer alloc] initWithFrame:CGRectMake(190, 290, 120, 160)];
viewer3.cameraType = AVCaptureDevicePositionBack; //Optional. Set to AVCaptureDevicePositionFront by default.
viewer3.session = session; //Optional
//viewer3.cameraType = AVCaptureDevicePositionBack; //Optional. Set to AVCaptureDevicePositionFront by default.
//viewer3.session = session; //Optional
viewer3.draggable = YES;
[viewer3 startFaceCam];
[self.view addSubview:viewer3];
*/
*/
}

- (void)didReceiveMemoryWarning
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ viewer3.cameraType = AVCaptureDevicePositionBack;
AVCaptureSession *session = [[AVCaptureSession alloc] init];
viewer3.session = session;
viewer3.draggable = YES;
[viewer3 startFaceCam];
[self.view addSubview:viewer3];
```
Expand All @@ -52,6 +54,8 @@ cameraType (*Optional*)

session (*Optional*) - sets AVCaptureSession

draggable (*Optional*) - allows view to be draggable

## Contact

Jason Everett
Expand Down

0 comments on commit 82f4c94

Please sign in to comment.