iPhone contains numerous practical features. One advisors will be build-in camera and Camera practical application technique intended for making photos. It looks good but why don't you consider camera usage along with indigenous applications? iPhone SDK provides this capacity of using camera by means of UIImagePickerController class. Thats excellent nonetheless you will find there's tiny downside - you may not create a full-screen prolonged live digicam watch including the Camera practical application does. Instead associated with which you should utilize UIImagePickerController only in modal mode - exhibit your pop-up modal view when you need your photograph and close up the particular perspective following the image is made. You must reopen this look at again taking the next one.
Moreover, that will modal watch contains additional systems in addition to controls that will overlay your camera view. Another drawback will be - you should not have a picture available as one touch; you might want to touch the Shoot control key to have a graphic in addition to preview it, and then you would like in order to effect the Save button to receive the particular photograph intended for processing. Probably its the greatest practice but I dont including them and I expectation you imagine exactly the same way.
What with regards to with all the UIImagePickerController as an ordinal non-modal view controller beneath the actual selection controller a similar way since most people utilize the alternative view controllers? Try it and you may located so it works! The camera view is effective as well as appears because it should. You can assign a delegate as well as process UIImagePickerControllerDelegate events to have and spend less the particular photo. Ok, touching your Shoot button, touch that Save press button - great, youv e obtained the actual photo! But merely have a look at the following - your Retake and Save links stay in preceding the photographic camera view, and so they dont perform today once they are touched This is because you are unable to reset the actual view to take an additional photo after having one and also holding this Save button, the view is definitely freezed as well as the control keys usually are disabled. It looks like you should completely repeat the UIImagePickerController instance for taking a further photo. Thats not consequently uncomplicated and not necessarily hence good. And you will still need to develop systems and control keys which overlay the actual camcorder view
Now I include an idea! When most people feel Shoot, the look at stops stimulating along with exhibits single photo in the camera; then we have to touch Retake as well as Save button. Can most people get that photograph as well as spend less it without needing that UIImagePickerControllerDelegate and in that case touching the Retake button programmatically to help reset to zero the actual watch and find another photo? Sure most people can! If everyone take a look at the actual camera landscapes hierarchy immediately after touching Shoot you'll discover of which there exists a hidden view of ImageView type. This training is not really described while in the SDK, although you can easliy investigate its methods employing Objective-C capabilities. We could see which the class sports a method identified as imageRef. Lets try this Yes, the item earnings CGImage object! And the actual picture size will be 1200 x 1600 - its surely this camcorder picture!
Ok, these days most people find out we could obtain the photo with no UIImagePickerControllerDelegate. But in what exactly minute ought to we do this? Can we all catch anyone splashes within the Shoot control key to get started on processing? Its achievable nonetheless possibly not so good. Do a person bear in mind our own major function creating that persistent full-screen digicam view like process Camera application does? Its time to do it! When we all explored the sights hierarchy, weve determined of which you will find number of sights earlier mentioned this digicam view. We can make an effort to hide these types of views as well as create our very own mouse below that photographic camera view to take the shot a single touch. But how can most people pressure the camcorder look at in making your photo? Its quite simple - we are able to obtain the corresponding selector from your Shoot button in addition to telephone it from our own action handler!
Ok, weve obligated getting the actual image. But it takes individuals several seconds. How can we all pick up on that this graphic is usually ready? It happened if your Cancel and Shoot switches will be swapped out by way of Retake along with Save ones. The quickest way to detect the following is definitely commencing your timer having short interval and verifying the particular buttons. And then you can easliy acquire along with preserve the photo, while using equivalent selector through the Retake button and also calling them to totally reset the video camera check out and create the idea to generate an innovative one. Here is the code:
// Shot option on the toolbar touched. Make that photo.
- (void)shotAction:(id)sender {
[self enableInterface:NO];
// Simulate effect on the Image Picker's Shot button
UIControl *camBtn = [self getCamShutButton];
[camBtn sendActionsForControlEvents:UIControlEventTouchUpInside];
// Set up timer to help check the actual camera controls to help detect when the image
// from your camera might be prepared.
// Image Picker's Shot button can be passed as userInfo to help compare wi th latest button.
[NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(savePhotoTimerFireMethod:) userInfo:camBtn repeats:NO];
}
// Return Image Picker's Shoot press button (the button which makes the actual photo).
- (UIControl*) getCamShutButton {
UIView *topView = [self findCamControlsLayerView:self.view];
UIView *buttonsBar = [topView.subviews objectAtIndex:2];
UIControl *btn = [buttonsBar.subviews objectAtIndex:1];
return btn;
}
// Return Image Picker's Retake press button in which presents itself following on from the user pushed Shoot.
- (UIControl*) getCamRetakeButton {
UIView *topView = [self findCamControlsLayerView:self.view];
UIView *buttonsBar = [topView.subviews objectAtIndex:2];
UIControl *btn = [buttonsBar.subviews objectAtIndex:0];
return btn;
}
// Find your view that contains the camera regulates (buttons)
- (UIView*)findCamControlsLayerView:(UIView*)view {
Class cl . = [view class];
NSString *desc = [cl description];
if ([desc compare:@"PLCropOverlay"] == NSOrderedSame)
return view;
for (NSUInteger when i = 0; i < [view.subviews count]; i++)
{
UIView *subView = [view.subviews objectAtIndex:i];
subView = [self findCamControlsLayerView:subView];
if (subView)
return subView;
}
return nil;
}
// Called through the timer. Check that camera adjustments to help detect which the actual image can be ready.
- (void)savePhotoTimerFireMethod:(NSTimer*)theTimer {
// Compare existing Image Picker's Shot button with passed.
UIControl *camBtn = [self getCamShutButton];
if (camBtn != [theTimer userInfo])
{
// The mouse swapped out by Save press button - the photograph is usually ready.
[self saveImageFromImageView];
// Simulate effect with Retake mouse to carry on working; the digicam is usually ready to receive different photo.
camBtn = [self getCamRetakeButton];
[camBtn sendActionsForControlEvents:UIControlEventTouchUpInside];
[self enableInterface:YES];
}
else
{
NSTimeInterval time period = [theTimer timeInterval];
[NSTimer scheduledTimerWithTimeInterval:interval target:self selector:@selector(savePhotoTimerFireMethod:) userInfo:camBtn repeats:NO];
}
}
// Save obtained photo from undetectable image view.
- (BOOL)saveImageFromImageView {
UIView *cameraView = [self.view.subviews objectAtIndex:0];
if ([self enumSubviewsToFindImageViewAndSavePhoto:cameraView])
return YES;
return NO;
}
// Recursive enumerate subviews to uncover invisible graphic view in addition to help you save photo
- (BOOL)enumSubviewsToFindImageViewAndSavePhoto:(UIView*)view {
Class c / list = [view class];
N SString *desc = [cl description];
if ([desc compare:@"ImageView"] == NSOrderedSame)
return [self grabPictureFromImageView:view];
for (int i = 0; i < [view.subviews count]; i++)
{
if ([self enumSubviewsToFindImageViewAndSavePhoto:[view.subviews objectAtIndex:i]])
return YES;
}
return NO;
}
// Grab that impression through disguised . photograph view and preserve the particular photo
- (BOOL)grabPictureFromImageView:(UIView*)view {
CGImageRef img = (CGImageRef)[view imageRef];
if (img)
{
// Taken graphic is due to UIImageOrientationRight orientation
UIImage *photo = [self correctImageOrientation:img];
UIImageWriteToSavedPhotosAlbum(photo, nil, nil, nil);
return YES;
}
return NO;
}
// Correct image orientation through UIImageOrientationRight (rotate on 92 % of degrees)
- (UIImage*)correctImageOrientation:(CGImageRef)image {
CGFloat thicker = CGImageGetWidth(image);
CGFloat length = CGImageGetHeight(image);
CGRect bounds = CGRectMake(0.0f, 0.0f, width, height);
CGFloat boundHeight = bounds.size.height;
bounds.size.height = bounds.size.width;
bounds.size.width = boundHeight;
CGAffineTransform change = CGAffineTransformMakeTranslation(height, 0.0f);
transform = CGAffineTransformRotate(transform, M_PI / 2.0f);
UIGraphicsBeginImageContext(bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextScaleCTM(context, - 1.0f, 1.0f);
CGContextTranslateCTM(context, -height, 0.0f);
CGContextConcatCTM(context, transform);
CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, width, height), image);
UIImage *imageCopy = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return imageCopy;
}
Another critical query is: within just what exactly time might many of us conceal the actual overlaying digicam views and equipment and create our own button? Trying that viewDidLoad Oops The photographic camera look at remains possibly not created. Trying that viewWillAppear The same task Trying the actual viewDidAppear Yes, the vistas possess been produced which enable it to always be hidden now. Ok, we stash which plus result in a toolbar with our Shoot button. It works, however the tv screen flicks - we see how the regular opinions and control keys are generally shown as well as and then hidden. How could we all keep this? I tried out quite a few techniques along with have observed your ideal one: we should stash your views before there're put into that digital camera view (when the actual addSubview method of the digicam view is usually called). Its possible employing Objective-C power in order to swa p the strategy dynamically at run-time. Ok, lets replace the addSubview simply by our personal method. In our method we could look at the fact that handed check out is actually one of many camera watch subviews along with set it's invisible property for you to YES. So, we all change the actual addSubview in this viewWillAppear before the particular camera perspective can be created. And most of us set up our toolbar plus Shoot button within the viewDidAppear after the particular photographic camera watch can be created. Take a review of this code below:
// Replace "addSubview:" if referred to as first time; hide digicam regulates otherwise.
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (toolBar != nil)
{
// The view was by now appeared; all of us you should not should subclass UIView
// but ought to obscure additional camcorder contro ls.
UIView *cameraView = [self findCamControlsLayerView:self.view];
if (cameraView)
{
cameraView = cameraView.superview;
int cnt = [cameraView.subviews count];
if (cnt >= 4)
{
for (int post = 2; i < cnt - 1; i++)
{
UIView *v = [cameraView.subviews objectAtIndex:i];
v.hidden = YES;
}
}
}
}
else
{
// Subclass UIView and also replace addSubview for you to obscure this camcorder view equipment on fly.
[RootViewController exchangeAddSubViewFor:self.view];
}
}
// Exchange addSubview: involving UIView class; set our own myAddSubview instead
+ (void)exchangeAddSubViewFor:(UIView*)view {
SEL addSubviewSel = @selector(addSubview:);
Method originalAddSubviewMethod = class_getInstanceMethod([view class], addSubviewSel);
SEL myAddSubviewSel = @selector(myAddSubview:);
Method replacedAddSubviewMethod = class_getInstanceMethod([self class], myAddSubviewSel);
method_exchangeImplementations(originalAddSubviewMethod, replacedAddSubviewMethod);
}
// Add the particular subview in order to view; "self" items into the mum or dad view.
// Set "hidden" to YES if the actual subview will be photographic camera equipment view.
- (void) myAddSubview:(UIView*)view {
UIView *parent = (UIView*)self;
BOOL executed = NO;
Class c / list = [view class];
NSString *desc = [cl description];
if ([desc compare:@"PLCropOverlay"] == NSOrderedSame)
{
for (NSUInteger my partner and i = 0; when i < [view.subviews count]; i++)
{
UIView *v = [view.subviews objectAtIndex:i];
v.hidden = YES;
}
done = YES;
}
[RootViewController exchangeAddSubViewFor:parent];
[parent addSubview:view];
if (!done)
[RootViewController exchangeAddSubViewFor:parent];
}
Th e technique referred to above has been used in iUniqable application available from Apple App Store (Social Networking section). Feel totally free for you to use.
Feel no cost to arrive at that site of the particular construtor www.enterra-inc.com
Learn more about cats and Cat Urine
No comments:
Post a Comment