After imageview picker disable view are not set fixed frame - iphone

How to solve this problem?
click Add button open image video add
After disble imagepickerview show this view
How can i solve this problem?

Try This code :
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
[application setStatusBarStyle:UIStatusBarStyleLightContent];
self.window.clipsToBounds =YES;
self.window.frame = CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
self.window.bounds = CGRectMake(0, 20, self.window.frame.size.width, self.window.frame.size.height);
}
return YES;
}

Related

Issue in hiding UINavigationBar in ios

I have a split view controller in my app's contact page.. and i am unable to hide the navigation bar in my page.. Can anyone help me on hiding the navigationBar. i have attached my code
- (void)viewDidLoad
{
self.navigationController.navigationBarHidden = YES;
splitViewController.navigationController.navigationBarHidden = YES;
appdelegate = (AppDelegate*)[[UIApplication sharedApplication]delegate];
[super viewDidLoad];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
[[VHeaderView sharedVHeaderView] viewWithCommonHeaderOnView1:self.view];
}
else
{
[[VHeaderView_iPad sharedVHeaderView_iPad] viewWithCommonHeaderOnView1:self.view];
}
[splitViewController.view setFrame:CGRectMake(0,48, 768, 1024)];
// [self.view removeFromSuperview];
//self.view.frame=CGRectMake(0,100, 768, 1024);
[self.view addSubview:splitViewController.view];
}
Try this. works for me. Make sure that navigation controller is allocated.
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES];
}
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO];
}
- (void)viewWillAppear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:YES animated:animated];
[super viewWillAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:NO animated:animated];
[super viewWillDisappear:animated];
}
put this code in your .m file
if u don't wish to animated effect then set no.
Callled only once this method.
try to put your code in ViewWillAppear
-(void)viewWillAppear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:YES animated:animated];
}
try this code

Not able to open UIImagePickerController

I am using this code in my button action function:
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.allowsEditing = NO;
picker.wantsFullScreenLayout = YES;
[self presentViewController:picker animated:YES completion:nil];
I am implementing the delegate also. UIImagePickerControllerDelegate
But it gets crashed at
[self presentViewController:picker animated:YES completion:nil];
Can som one help me out on what I am doing wrong?
This is for IOS 6. These delegate methods are supported only in IOS 6.
I got the answer to my own question. My application was developed for landscape mode only. So the imagePickerView was not able to present itself as its default orientation is landscape. So I made my application supported for landscape and portrait mode. In the app delegate I used the method,
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
return UIInterfaceOrientationMaskAll;
else /* iphone */
return UIInterfaceOrientationMaskAllButUpsideDown;
}
And in the rootViewController I used the following delegates to force the viewController to be in landscape mode and remain in landscape mode.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(interfaceOrientation == UIInterfaceOrientationLandscapeRight)
return YES;
else
return NO;
}
- (BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
And it worked.

Open a Specific View controller when user launch UILocalNotification in ViewBased Application

I am working with UILocalNotification.Here When i Launch the notification i need a specific view in application.But I have tried like below coding .
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[[UIApplication sharedApplication]setStatusBarHidden:NO];
SplashView *mySplash = [[SplashView alloc] initWithImage:
[UIImage imageNamed:#"Splash.png"]];
[window insertSubview:mySplash atIndex:1];
[window makeKeyAndVisible];
mySplash.delay = 5;
mySplash.animation = SplashViewAnimationFade;
[mySplash startSplash];
[self.window insertSubview:viewController.view atIndex:0];
[self.window makeKeyAndVisible];
[mySplash release];
// Add the view controller's view to the window and display. [self.window addSubview:viewController.view];
UILocalNotification *localNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotification)
{
NSLog(#"Notification Body: %#",localNotification.alertBody);
NSLog(#"%#", localNotification.userInfo);
}
[[UIApplication sharedApplication] cancelAllLocalNotifications];
application.applicationIconBadgeNumber = 0;
return YES;
}
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateInactive) {
showItemContrller = [[Showitem alloc] initWithNibName:#"Showitem" bundle:nil];
[self.window addSubview:showItemContrller.view];
[self.window bringSubviewToFront:showItemContrller.view];
}
}
But When i launch the notification it is showing the previous view for fraction of seconds the it is going to showItemControllerView.
Thanking you
//comment this line....
//[self.window insertSubview:viewController.view atIndex:0];

Set UIBarStyle of UIImagePickerController

I would like to set the bar style of a UIImagePickerController as following, but the bar is still UIBarStyleBlackTranslucent. Is it possible to set the bar style of UIImagePickerController? Thanks in advance!
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.navigationBar.barStyle = UIBarStyleBlack;
Edit 1
I can set the tint color through:
imagePicker.navigationBar.tintColor = UIColorFromRGB(0xCC6600);
Here's what worked for me (you need to test the class of the navigationController, not the viewController being presented, and you need to set a non-transparent background color as well it seems)
- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController
animated:(BOOL)animated
{
if ([navigationController isKindOfClass:[UIImagePickerController class]])
{
navigationController.navigationBar.barStyle = UIBarStyleBlack;
navigationController.navigationBar.backgroundColor = [UIColor blackColor];
}
}
imagePicker.navigationBar.tintColor=[UIColor blackColor];
You can make the change by implementing the UINavigationControllerDelegate method navigationController:willShowViewController:, like this:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController
animated:(BOOL)animated {
if([viewController isKindOfClass:[UIImagePickerController class]])
navigationController.navigationBar.barStyle = UIBarStyleBlack;
}

didAnimateFirstHalfOfRotationToInterfaceOrientation iOS5 replacement

didAnimateFirstHalfOfRotationToInterfaceOrientation is deprecated in iOS 5.0. However I would like to use this method in my application. I am using the sample code that Apple offers in the iOS Dev Center, project name AlternateViews. I would like the app to rotate the portraitView while fading in the landscapeView. Can this be done in iOS 5 or is this feature forever gone?
portraitView currently calls:
[self presentModalViewController:self.landscapeViewController animated:YES];
while landscapeView calls this in code in the init method:
self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
It appears all of the animation is done in the following PortraitViewController.m:
#import "PortraitViewController.h"
#import "LandscapeViewController.h"
#implementation PortraitViewController
#synthesize landscapeViewController;
- (void)viewDidLoad
{
self.view.backgroundColor = [UIColor colorWithRed:197.0/255.0 green:204.0/255.0 blue:211.0/255.0 alpha:1.0];
LandscapeViewController *viewController = [[LandscapeViewController alloc]
initWithNibName:#"LandscapeView" bundle:nil];
self.landscapeViewController = viewController;
[viewController release];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (void)viewDidUnload
{
self.landscapeViewController = nil;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
[landscapeViewController release];
[super dealloc];
}
- (void)orientationChanged:(NSNotification *)notification
{
// We must add a delay here, otherwise we'll swap in the new view
// too quickly and we'll get an animation glitch
[self performSelector:#selector(updateLandscapeView) withObject:nil afterDelay:0];
}
- (void)updateLandscapeView
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView)
{
[self presentModalViewController:self.landscapeViewController animated:YES];
isShowingLandscapeView = YES;
}
else if (deviceOrientation == UIDeviceOrientationPortrait && isShowingLandscapeView)
{
[self dismissModalViewControllerAnimated:YES];
isShowingLandscapeView = NO;
}
}
// override to allow orientations other than the default portrait orientation
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait); // support only portrait
}
#end
Here is my current implementation files which fail miserably.
PortraitViewController.m:
#import "PortraitViewController.h"
#import "LandscapeViewController.h"
#implementation PortraitViewController
#synthesize landscapeViewController;
- (void)viewDidLoad
{
LandscapeViewController *viewController = [[LandscapeViewController alloc]
initWithNibName:#"LandscapeView" bundle:nil];
self.landscapeViewController = viewController;
[viewController release];
NSLog(#"Portrait viewDidLoad");
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:NO];
}
- (void)viewDidUnload
{
self.landscapeViewController = nil;
}
- (void)dealloc
{
[landscapeViewController release];
[super dealloc];
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (toInterfaceOrientation == UIInterfaceOrientationPortrait) {
NSLog(#"Portrait-willAnimateRotationToInterfaceOrientation Portrait");
} else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
NSLog(#"Portrait-willAnimateRotationToInterfaceOrientation Landscape");
}
[self performSelector:#selector(updateLandscapeView) withObject:nil afterDelay:0];
}
- (void)updateLandscapeView
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView)
{
NSLog(#"Portrait-present Landscape");
[self presentModalViewController:self.landscapeViewController animated:YES];
isShowingLandscapeView = YES;
}
else if (deviceOrientation == UIDeviceOrientationPortrait && isShowingLandscapeView)
{
NSLog(#"Portrait-dismiss Landscape");
[self dismissModalViewControllerAnimated:YES];
isShowingLandscapeView = NO;
}
}
// override to allow orientations other than the default portrait orientation
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
return NO;
else
return YES;
}
#end
LandscapeViewController.m
#import "LandscapeViewController.h"
#implementation LandscapeViewController
// the designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])
{
self.wantsFullScreenLayout = YES; // we want to overlap the status bar.
// when presented, we want to display using a cross dissolve
self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
}
return self;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
oldStatusBarStyle = [[UIApplication sharedApplication] statusBarStyle];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:NO];
NSLog(#"Landscape viewWillAppear");
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[[UIApplication sharedApplication] setStatusBarStyle:oldStatusBarStyle animated:NO];
}
// override to allow orientations other than the default portrait orientation
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// return YES for supported orientations
if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
return NO;
else
return YES;
//return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (toInterfaceOrientation == UIInterfaceOrientationPortrait) {
NSLog(#"Landscape-willAnimateRotationToInterfaceOrientation Portrait");
[self dismissModalViewControllerAnimated:YES];
} else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
NSLog(#"Landscape-willAnimateRotationToInterfaceOrientation Landscape");
}
}
#end
In Apple's UIViewController reference page, you'll find this useful paragraph in the "Handling View Rotations" section:
If you want to perform custom animations during an orientation change,
you can do so in one of two ways. Orientation changes used to occur in
two steps, with notifications occurring at the beginning, middle, and
end points of the rotation. However, in iOS 3.0, support was added for
performing orientation changes in one step. Using a one-step
orientation change tends to be faster than the older two-step process
and is generally recommended for any new code.
To add animations for an orientation change, override the
willAnimateRotationToInterfaceOrientation:duration: method and perform
your animations there.
Could you override the willAnimateRotationToInterfaceOrientation: method to do your animations?