How to hide/unhide the status bar, tab bar and navigation bar on touch using TapGesture.
Can anyone give me the code for it?
Adding a tap gesture to the view
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(hideUIComponents:)];
[self.view addGestureRecognizer:tapGestureRecognizer];
Then the function hideUIComponents
- (void)hideUIComponents:(UITapGestureRecognizer*)tapGesture
{
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
[[self navigationController] setNavigationBarHidden:YES animated:YES];
CATransition *animation = [CATransition animation];
[animation setType:kCATransitionMoveIn];
[[self.view.window layer] addAnimation:animation forKey:#"layerAnimation"];
[self.tabBarController.tabBar setHidden:YES];
}
Unhide by reversing the values. I hope this helps.
You want to do it on tap gesture
Then use
[[UITapGestureRecognizer alloc]initWithTarget:self action:#selector(ViewTapped:)]
on the view that where you want to implement.
check whether status bar is hidden or not using
[[UIApplication sharedApplication] isStatusBarHidden];
and then
To hide status bar use:
[[UIApplication sharedApplication] setStatusBarHidden:YES];
and to show it again use:
[[UIApplication sharedApplication] setStatusBarHidden:NO];
Related
In my view controller's I have following code
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSLog(#"%s",__PRETTY_FUNCTION__);
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:201.0/255.0 green:201.0/255.0 blue:201.0/255.0 alpha:1.0];
}
On this view when I click a button , I am presenting MFMailComposeViewController modally. When I present MFMailComposeViewController modally, navigation bar same color as set in viewWillAppear. I want default blue color as Apple told that don't customize this view. Here is my code which I have tried
Code 1:
-(void)sendEmailWithWithRecipients:(NSArray*)recipients andData:(NSData*)data {
if ([MFMailComposeViewController canSendMail]){
MFMailComposeViewController *mailComposeViewController = [[MFMailComposeViewController alloc] init];
mailComposeViewController.mailComposeDelegate = self;
self.navigationController.navigationBar.tintColor = nil;
[self presentModalViewController:mailComposeViewController animated:YES];
[mailComposeViewController release];
}
else {
[self showAlertWithTitle:#"Alert" andMessage:#"Can not send email. Please check your email settings."];
}
}
But above code is not working for tint color
Code 2: Set tint color in viewWillDisappear
-(void)viewWillDisappear:(BOOL)animated {
NSLog(#"%s",__PRETTY_FUNCTION__);
self.navigationController.navigationBar.tintColor = nil;
[super viewWillDisappear:animated];
}
Code 2 also not working.
But this is working fine in iOS5 without setting tintColor = nil while presenting MFMailComposeViewController modally & in viewWillDisappear. Its not working iOS 4.x
Anyone have solution for this? Thanks.
You can customize the navigationbar's tint color by accessing yourController's(ViewController which you are presetnting) topViewController.
Ex :
[self presentModalViewController:yourController animated:YES];
yourController.topViewController.navigationController.navigationBar.tintColor =
[UIColor (Your Color)];
Try setting the navigation bar style rather than the tint color. Tint color and bar style have slightly different side effects, so while I don't completely understand your needs, it might be exactly what you're looking for.
[self.navigationController.navigationBar setBarStyle:UIBarStyleDefault];
or
self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
And make sure you do this within the context of the modal view controller, not the previous view controller.
Instead of nil try this [UIColor ClearColor];
I have a tableView, and a "Reload" button that fetches data from a URL and reloads the table, a costly operation (in particular the fetch part).
I want display info to the user while this is happening, so I thought I'd put up a "Loading" UITextView on top, do the fetch/reload operation, then remove the UITextView.
Here's the code:
- (IBAction)refreshData:(id)sender {
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height-30, self.view.frame.size.width, 30)];
[self.view addSubview:textView];
textView.text = #"Loading..";
textView.textColor = [UIColor whiteColor];
textView.backgroundColor = [UIColor grayColor];
textView.editable = NO;
[self fetchData];
[self.tableView reloadData];
[textView removeFromSuperview];
}
The behavior I get is that the fetchData executes before the UITextView renders on screen. I know this because I have NSLogs inside fetchData that execute before the UITextView shows up on screen.
Is there something obvious I'm missing here? Thanks.
Replace [self fetchData]; with
[self performSelectorInBackground:#selector(fetchData) withObject:nil];
Then inside your fetchData method, after your fetch is done, add
[self performSelectorOnMainThread:#selector(fetchDataFinished) withObject:nil waitUntilDone:NO];
where the new method fetchDataFinished is defined as
-(void) fetchDataFinished{
[self.tableView reloadData];
[self.textView removeFromSuperview];
}
Note that you have to make textView a property so it is accessible in this method.
I have not tried out the above for your particular case, but I have used similar constructs successfully in many similar situations.
I have tried hiding a segmented controller just like a button or label can be hidden in XCode. It's intended to be hidden/shown when touching a parent segmented controller above. This Code would work with Buttons or Labels:
mySegmContr.hidden = YES;
But it just won't work for segmented controllers. Can you help me out?
I figured out that you can use a simple UIView in which you put the things you want to hide. The UIView can then be hidden with
myView.hidden = YES;
still I found no way to hide a segmented control directly.
If you create a property for the segment controller you can do more stuff with it like changing it's location, resizing it and want you want hiding it.
In your .h file do this
UISegmentedControl *mySegment;
#property (nonatomic, retain) UISegmentedControl *mySegment;
-(void) createMySegment;
In your .m file do this
#synthesize mySegment;
- (void) createMySegment {
if ([self mySegment] == nil) {
NSArray *buttons = [NSArray arrayWithObjects:#"One", #"Two", #"Three", nil];
UISegmentedControl *segName = [[UISegmentedControl alloc] buttons];
[self setMySegment:segName];
[segName release];
segName.frame = CGRectMake(110, 62, 120, 25);
segName.segmentedControlStyle = UISegmentedControlStyleBar;
segName.momentary = NO;
segName.selectedSegmentIndex = 0;
[segName addTarget:self
action:#selector(pickMethod:)
forControlEvents:UIControlEventValueChanged];
[self.view addSubview:segName];
}
}
NOTE: With "setMySegment" above make sure you use a capital first letter which is M in "mySegment".
Then when you want to hide it use this. Don't for get to dealloc mySegment.
[[self mySegment] setHidden:YES];
I have a simple in app SMS view slide up when a button is pressed.
However in the Info.plist I have the status bar set to Opaque black style, but when the SMS view is shown the status bar changes to gray. And then changes back once the SMS view is dismissed.
this is the SMS code...
if([MFMessageComposeViewController canSendText])
{
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
NSString *MessageString = [NSString stringWithFormat:#"%# %#%#",Label2.text, Label4.text, Label1.text];
controller.body = MessageString;
controller.navigationBar.tintColor = [UIColor blackColor];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
Has else anyone run into this?
Is there a way to have the SMS view not change the status bar color?
Try this after you present the controller,
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
I have created navigation based project. and in second screen i want to add uitabbarcontroller. so can any one suggest how i do this.
i already did lot of search but no success yet. so please can you provide a simple sample of this. i already tried below discussion but i think its not a good approach.
Navigation Based Application with TabBar
Thanks
Actually this is the correct approach. The one thing that is not correct is where the controllers are allocated. This is happened in the previous controller, the one that is making the push, but should be allocated in the object that is responsible, the TabBarController.
When you implement your action to show the UITabBarController make the following code:
- (void) theAction {
SomeTabBarControllerSubClass *controller = [[SomeTabBarControllerSubClass alloc] init];
[self.navigationController pushViewController:controller animated:YES];
[controller release];
}
Then when you implement the SomeTabBarControllerSubClass class:
(.h)
#interface SomeTabBarControllerSubClass : UITabBarController {
UIViewController *first;
UIViewController *second;
}
#end
(.m)
#implementation SomeTabBarControllerSubClass
- (void) viewDidLoad {
first = [[UIViewController alloc] init]; //Or initWithNib:
second = [[UIViewController alloc] init];
first.view.backgroundColor = [UIColor greenColor] //Just example
second.view.backgroundColor = [UIColor redColor] //Just example
first.tabBarItem.image = [UIImage imageNamed:#"someImage.png"];
self.viewControllers = [NSArray arrayWithObjects:first,second,nil];
}
- (void) dealloc {
[first dealloc];
[second dealloc];
[super dealloc];
}
#end