I am creating the simple customized camera application.
so. i tried to customize the buttons for flash setting button and capture.
It worked for iPhone4 and iPhone4s... but unfortunately.. it shows the white screen on iPhone3gs.
What's the problem?
#define CAMERA_TRANSFORM_X 1
#define CAMERA_TRANSFORM_Y 1
#define SCREEN_WIDTH 320
#define SCREEN_HEIGTH 480
- (void) showCamera
{
overlay = [[CustomOverlayView alloc]
initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGTH)];
overlay.delegate = self;
self.picker = [[UIImagePickerController alloc] init];
self.picker.delegate = self;
self.picker.navigationBarHidden = YES;
self.picker.toolbarHidden = YES;
self.picker.wantsFullScreenLayout = YES;
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.showsCameraControls = NO;
self.picker.cameraViewTransform = CGAffineTransformScale(self.picker.cameraViewTransform, CAMERA_TRANSFORM_X, CAMERA_TRANSFORM_Y);
self.picker.cameraOverlayView = overlay;
[self.view addsubview self.picker.view];
}
Call your showCamera method in your root view controller viewDidLoad method, or in its init method if you don't use IB.
You should present your camera controller by using
[self.navigationController presentModalViewContoller:self.picker animated:NO];
Related
How to get UIImagePickerController in iOS 7 Look like the same screen that show in the attached screen shot with out using Overlay Controller.
This is the code am using for picker controller.
UIImagePickerController *eImagePickerController = [[UIImagePickerController alloc] init];
eImagePickerController.delegate=self;
eImagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
eImagePickerController.cameraDevice = UIImagePickerControllerSourceTypeCamera;
eImagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
eImagePickerController.showsCameraControls = YES;
eImagePickerController.navigationBarHidden = NO;
eImagePickerController.cameraDevice=UIImagePickerControllerCameraDeviceRear;
eImagePickerController.wantsFullScreenLayout = NO;
eImagePickerController.cameraViewTransform = CGAffineTransformScale(eImagePickerController.cameraViewTransform, CAMERA_TRANSFORM_X, CAMERA_TRANSFORM_Y);
[self presentViewController:eImagePickerController animated:YES completion:nil];
The issue is shown in attached screenshot
The following code will present the UIImagePickerController in a way that resembles the screenshot given.
UIImagePickerController *eImagePickerController = [[UIImagePickerController alloc] init];
eImagePickerController.delegate = self;
eImagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
eImagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
eImagePickerController.cameraDevice= UIImagePickerControllerCameraDeviceRear;
eImagePickerController.showsCameraControls = YES;
eImagePickerController.navigationBarHidden = NO;
[self presentViewController:eImagePickerController animated:YES completion:nil];
Just make sure that you hide the status bar or it will be displayed in the UIImagePickerController as well.
I'm building a universal iOS app and the iPad version uses a SplitViewController. In the popover view, I have a UITabBarController with two buttons. When it runs on the iPhone, the TabBar buttons correctly stretch to fill the entire width of the view...
...but on the iPad, in the popover view, the buttons don't stretch to fill the entire width...
I'm creating the UITabBarController programmatically...
InspectionTabBarViewController *inspectionTabBarVC;
InspectionListViewController *inspectionListVC;
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
inspectionListVC = [[InspectionListViewController alloc] initWithSunday:NO];
inspectionListVC.managedObjectContext = self.managedObjectContext;
UINavigationController *calendarNavVC = [[UINavigationController alloc] initWithRootViewController:inspectionListVC];
calendarNavVC.title = #"Calendar";
InspectionMapViewController *mapViewVC = [[InspectionMapViewController alloc] initWithNibName:#"InspectionMapView_iPhone" bundle:nil];
UINavigationController *mapdNavVC = [[UINavigationController alloc] initWithRootViewController:mapViewVC];
mapdNavVC.title = #"Map";
inspectionTabBarVC = [[InspectionTabBarViewController alloc] init];
[inspectionTabBarVC addChildViewController:calendarNavVC];
[inspectionTabBarVC addChildViewController:mapdNavVC];
self.window.rootViewController = inspectionTabBarVC;
}
else
{
inspectionListVC = [[InspectionListViewController alloc] initWithSunday:NO];
UINavigationController *calendarNavVC = [[UINavigationController alloc] initWithRootViewController:inspectionListVC];
calendarNavVC.title = #"Calendar";
InspectionMapViewController *mapViewVC = [[InspectionMapViewController alloc] initWithNibName:#"InspectionMapView_iPad" bundle:nil];
UINavigationController *mapdNavVC = [[UINavigationController alloc] initWithRootViewController:mapViewVC];
mapdNavVC.title = #"Map";
inspectionTabBarVC = [[InspectionTabBarViewController alloc] init];
[inspectionTabBarVC addChildViewController:calendarNavVC];
[inspectionTabBarVC addChildViewController:mapdNavVC];
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailViewController_iPad" bundle:nil];
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
self.splitViewController = [[UISplitViewController alloc] init];
self.splitViewController.delegate = detailViewController;
self.splitViewController.viewControllers = [NSArray arrayWithObjects:inspectionTabBarVC, detailNavigationController, nil];
self.window.rootViewController = self.splitViewController;
inspectionListVC.detailViewController = detailViewController;
inspectionListVC.managedObjectContext = self.managedObjectContext;
detailViewController.detailViewControllerDelegate = inspectionListVC;
}
[self.window makeKeyAndVisible];
I also tried setting the autoResizeMask inside the InspectionTabBarViewController's loadView method using the following statement...
self.tabBar.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth;
...but that didn't work either. How can I get the UITabBar buttons to fill the entire width of of the view?
Thanks so much in advance for your help!
Change UITabBar property itemPositioning to UITabBarItemPositioningFill:
self.tabBar.itemPositioning = UITabBarItemPositioningFill;
Swift version:
tabBar.itemPositioning = .fill
UITabBar itemPositioning reference
This can actually be done by setting the setSelectionIndicatorImage on the tab bar. The buttons will resize to your image's width, regardless of iPhone or iPad.
The problem with this is that it's not dynamic, and every time you add or change the number of items in the tab bar, you'll have to create another image.
A solution is to create the image in code and calculate the width by ({tab bar width}/{# of tabbaritems}).
For example:
Where you create the tab bar:
[[self.tabBarController tabBar] setSelectionIndicatorImage:[self selectionIndicatorImage]];
The image method:
- (UIImage *)selectionIndicatorImage
{
NSUInteger count = [[self.tabBarController viewControllers] count];
CGSize tabBarSize = [[self.tabBarController tabBar] frame].size;
NSUInteger padding = 2;
CGSize buttonSize = CGSizeMake( tabBarSize.width / count, tabBarSize.height );
UIGraphicsBeginImageContext( buttonSize );
CGContextRef c = UIGraphicsGetCurrentContext();
[[UIColor colorWithWhite:0.9 alpha:0.1] setFill];
UIBezierPath *roundedRect = [UIBezierPath bezierPathWithRoundedRect:CGRectMake( padding, padding * 2, buttonSize.width - (padding * 2) , buttonSize.height - ( padding * 2 ) ) cornerRadius:4.0];
[roundedRect fillWithBlendMode: kCGBlendModeNormal alpha:1.0f];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
CGContextRelease( c );
return image;
}
We can not set size for the UITabbarItem dynamically.
In iPhone it sets (Devices Width/no of Tabbaritems)
In iPad it sets with specific width
If you want to create such kind of view, then go with custom buttons which looks like tab bar buttons and add functionality by your code for the same.
I found itemWidth(property of UITabBar) in iOS7.
UITabBar reference
#implementation MainViewController
#synthesize scrollView,imageView;
- (id) init {
if (self != nil) {
self.title = #"Evolution";
}
return self;}
- (void)viewDidLoad {
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapDetected:)];
tapGesture.numberOfTapsRequired = 1;
tapGesture.numberOfTouchesRequired = 1;
scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
int numberOfImages = 32;
CGFloat currentX = 0.0f;
for (int i=1; i <= numberOfImages; i++) {
// create image
NSString *imageName = [NSString stringWithFormat:#"page-%d.jpg", i];
UIImage *image = [UIImage imageNamed:imageName];
imageView = [[UIImageView alloc] initWithImage:image];
// put image on correct position
CGRect rect = imageView.frame;
rect.origin.x = currentX;
imageView.frame = rect;
// update currentX
currentX +=454; //mageView.frame.size.width;
[scrollView addSubview:imageView];
[imageView release];
}
[scrollView addGestureRecognizer:tapGesture];
scrollView.contentSize = CGSizeMake(currentX, 800);
scrollView.pagingEnabled=YES;
scrollView.userInteractionEnabled = YES;
scrollView.maximumZoomScale = 15;
scrollView.minimumZoomScale = 0.5;
scrollView.bounces = NO;
scrollView.bouncesZoom = NO;
scrollView.delegate = self;
scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
[self.view addSubview:scrollView];
[scrollView release];
[super viewDidLoad];}
- (BOOL)shouldAutorotateToInterfaceOrientation(UIInterfaceOrientation)interfaceOrientation{
return YES;}
-(void)tapDetected:(UIGestureRecognizer*)recognizer{
ImageViewController *settings = [[ImageViewController alloc] init];
[self.navigationController pushViewController:settings animated:YES];
[settings release];}
#end
#implementation ImgScrollViewAppDelegate
#synthesize window;#synthesize viewController;
- (void)applicationDidFinishLaunching:(UIApplication *)application{
LogMethod();
// If you want the status bar to be hidden at launch use this:
// application.statusBarHidden = YES;
//
// To set the status bar as black, use the following:
// application.statusBarStyle = UIStatusBarStyleBlackOpaque;
// Create window
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// this helps in debugging, so that you know "exactly" where your views are placed;
// if you see "red", you are looking at the bare window, otherwise use black
// window.backgroundColor = [UIColor redColor];
viewController = [ [ MainViewController alloc ] init ];
navigationController = [ [ UINavigationController alloc ] initWithRootViewController: viewController ];
/* Anchor the view to the window */
[window addSubview:[navigationController view]];
/* Make the window key and visible */
[window makeKeyAndVisible];
}
#end
in above code i have problem that is when check it on simulator then rotate device left and right. But view not change and i want to change it. how i modify it?
In your view controller implementation there is a method - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation. If you want it to rotate to any orientation, make it return YES. If you only want it to autorotate to some orientations, add an if statement to check and return yes or no.
I have a viewcontroller that is set to scrollview delegate (the scrollview is a subview of the viewcontroller), when I put [scrollview removeFromSuperview]; both the viewcontroller and the scrollview get removed and I'm just left with an empty window.
How can I remove only the scrollview?
edit::::
this is part of my viewcontroller .h
#interface QuartzViewController : UIViewController <UIScrollViewDelegate> {
this is part of my viewcontroller .m
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
UIInterfaceOrientation o = self.interfaceOrientation;
if ((o == UIInterfaceOrientationPortrait) || (o == UIInterfaceOrientationPortraitUpsideDown)) {D = 1;pagingScrollView.delegate = nil;[pagingScrollView removeFromSuperview];[self resurrectPaging];}
if ((o == UIInterfaceOrientationLandscapeLeft) || (o == UIInterfaceOrientationLandscapeRight)) {D = 2;pagingScrollView.delegate = nil;[pagingScrollView removeFromSuperview];[self resurrectPaging];}}
-(void)resurrectPaging {
CGRect F;
F = [self frameForPagingScrollView];
pagingScrollView = [[UIScrollView alloc] initWithFrame:F];
[SELF addSubview:pagingScrollView];
[self setPaging];}
- (void)viewDidLoad {
[self.view addSubview:SELF];
D = 1;
CGRect F;
F = [self frameForPagingScrollView];
pagingScrollView = [[UIScrollView alloc] initWithFrame:F];
[self setPaging];}
- (void)setPaging {
if (D == 1) {
CGRect F;
F = [self frameForPagingScrollView];
pagingScrollView.pagingEnabled = YES;
pagingScrollView.backgroundColor = [UIColor whiteColor];
pagingScrollView.showsVerticalScrollIndicator = NO;
pagingScrollView.showsHorizontalScrollIndicator = NO;
pagingScrollView.contentSize = CGSizeMake(F.size.width * [self pdfPageCount], F.size.height);
pagingScrollView.delegate = self;
pagingScrollView.clipsToBounds = YES;
pagingScrollView.bounces = YES;
self.view = pagingScrollView;
recycledPages = [[NSMutableSet alloc] init];
visiblePages = [[NSMutableSet alloc] init];
[self tilePages];
[pagingScrollView addSubview:self.isvP];}
else if (D == 2) {
CGRect F;
F = [self frameForPagingScrollView];
pagingScrollView.pagingEnabled = YES;
pagingScrollView.backgroundColor = [UIColor redColor];
pagingScrollView.showsVerticalScrollIndicator = NO;
pagingScrollView.showsHorizontalScrollIndicator = NO;
pagingScrollView.contentSize = CGSizeMake(F.size.width * [self pdfPageCount], F.size.height);
pagingScrollView.delegate = self;
pagingScrollView.clipsToBounds = YES;
pagingScrollView.bounces = YES;
self.view = pagingScrollView;
recycledPages = [[NSMutableSet alloc] init];
visiblePages = [[NSMutableSet alloc] init];
[self tilePages];
[pagingScrollView addSubview:self.isvL];}}
basically the reason i what to remove then add my scrollview again is because when the device orientation changes to landscape my landscape subview is in the wrong place (x, y).
but say if i start off in landscape isvL is in the right place so I know I got the code correct. going to landscape screws the x, y positions of isvL in my pagingScrollView!
basically the reason i what to remove then add my scrollview again is because when the device orientation changes to landscape my landscape subview is in the wrong place (x, y).
If you having trouble with the positioning of your scroll view, you should try setting autoresize masks correctly, or manually adjusting the frame. There is no reason to remove and recreate a scroll view every time.
Also, in the code you have listed, you appear to be leaking your scroll view.
I used to use the old-school method of adding an overlay to the camera screen, and that worked fine. However, since 3.1 came out, Apple is insisting that I use the API to add an overlay. I quickly got the overlay to work, but it seems that if I use the custom overlay, then the move & resize screen is not responsive, I can only use or retake, can't actually resize & move. The code I am using is below. I have tried several variations, but the only thing that actually enables the move & resize is to remove the line that adds the custom overlay view.
Any ideas?
UIImage *image = [UIImage imageNamed:#"camera-template-long.png"];
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)] ;
imgView.image = image;
UIView *overlayView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
overlayView.opaque = NO;
[overlayView addSubview:imgView];
UIImagePickerController* picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls = YES;
picker.cameraOverlayView = overlayView;
picker.delegate = self;
picker.allowsEditing = YES;
[self presentModalViewController:picker animated:YES];
Set both allowsEditing/showsCameraControls properties to NO, prepare your original view to cameraOverlayView, and use takePicture method.
Then, imagePickerController:didFinishPickingMediaWithInfo: will be called directly.
Please try the following code:
- (void)foo {
UIImagePickerController *controller = [[[UIImagePickerController alloc] init] autorelease];
controller.sourceType = UIImagePickerControllerSourceTypeCamera;
controller.cameraOverlayView = self.cameraOverlay;
[self performSelector:#selector(moveOverlayViewToSublayer:) withObject:controller afterDelay:0.1f];
controller.delegate = self;
[self presentModalViewController:controller animated:YES];
}
- (void) moveOverlayViewToSublayer:(UIImagePickerController*)controller {
CALayer *aLayer = self.cameraOverlay.layer.superlayer;
controller.cameraOverlayView = nil;
[aLayer addSublayer:self.cameraOverlay.layer];
}
I hope it will work well.
The entire issue goes away once you use [overlayView setUserInteractionEnabled:NO]; to stop the overlay view from handling the input.
http://www.techques.com/question/1-10178214/cameraOverlayView-prevents-editing-with-allowsEditing
This works perfectly for me. I tried to disable userInteractionEnabled but in vain.