In my iOS app i've hidden the status bar with this code in each ViewController:
- (BOOL)prefersStatusBarHidden
{
return YES;
}
In a view I need to use a UIDocumentInteractionController, but when it comes up, the status bar appears, is there a way to keep it hidden?
Thanks in advance
Use a combination of the following code and the code from iOS:
- (UIViewController *) documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *) controller {
// hack to keep status bar visible
[[NSOperationQueue mainQueue] addOperationWithBlock:
^{
[[UIApplication sharedApplication] setStatusBarHidden:NO];
}];
return self;
}
combined with
- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller {
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
Try this works for me :
- (void)documentInteractionControllerWillBeginPreview:(UIDocumentInteractionController *)controller
{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller
{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
Set documentController.delegate to self and use
- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller {
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
Related
I have a QR code reader in my app. Once the reader scans a code, it takes the app to a survey page. I'm trying to get the survey page to hide the statusbar. Here is my code:
- (void)zxingController:(ZXingWidgetController*)controller didScanResult:(NSString *)result {
// self.resultsToDisplay = result;
if (self.isViewLoaded) {
[[NSBundle mainBundle] loadNibNamed:#"yellaViewController" owner:self options:nil];
initWithNibName:#"yellaViewController" bundle:[NSBundle mainBundle]];
[topImage setImage:[UIImage imageNamed:#"yellalogoREAL.png"]];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
This isn't working for me, and the statusbar stays visible. What am I doing wrong?
ALSO: Is there a way I can hide the tabbarcontroller on the surveypage using the same if statement?
In ZxingController's viewDidAppear: (ZxingWidgetController.m)
self.isStatusBarHidden = [[UIApplication sharedApplication] isStatusBarHidden];
if (!isStatusBarHidden)
[[UIApplication sharedApplication] setStatusBarHidden:YES];
it cached the previous statusbar state, and when you exit the ZxingController, in viewDidDisappear:
if (!isStatusBarHidden)
[[UIApplication sharedApplication] setStatusBarHidden:NO];
Since the viewDidDisappear in ZxingController will enter after zxingController:didScanResult:
So your setStatusBarHidden in zxingController:didScanResult: is no use.
I am hiding the status bar in my application when I present my uiimagepickerviewcontroller modally.
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
In the callback method:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
I execute the following methods:
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES];
before calling:
[picker dismissViewControllerAnimated:YES completion:^() {}];
I've tried "showing" the status bar in the completion block to no avail. How should I go about in getting the status bar to reappear after dismissing my uiimagepickerviewcontroller?
Try putting it back in the view controllers dismissal completion handler:
[picker dismissViewControllerAnimated:YES completion:^(BOOL done){
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES];
}];
Although this is strange, there isn't any reason as to why this wouldn't be working jumping out at me.
I had the same problem in iOS 11. I could make the statusBar re-appear in the following way:
In Info.plist, set View controller-based status bar appearance to YES:
In the view controller that presents the UIImagePickerController, implement
- (BOOL)prefersStatusBarHidden {
return NO;
}
I am hiding the Status bar with the below code and it gives me a memory warning level1 . It does nothing to the app itself during the memory warning but I do not like to have such things happening. Is there somthing I am doing wrong? or and con someone confirm a IOS bug? Not a huge deal just bothering me , so any info is greatly appreciated. Thanks!
[[UIApplication sharedApplication] setStatusBarHidden:YES
withAnimation:UIStatusBarAnimationSlide];
Try this
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if([[UIApplication sharedApplication] respondsToSelector:#selector(setStatusBarHidden:withAnimation:)]) {
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
}
else {
id<UIApplicationDeprecatedMethods> app = [UIApplication sharedApplication];
[app setStatusBarHidden:YES animated:NO];
}
}
and declare in your .h
#protocol UIApplicationDeprecatedMethods
- (void)setStatusBarHidden:(BOOL)hidden animated:(BOOL)animated;
#end
Hope it helps..
I am showing a particular website in UIWebView were it shows the entire website.
The problem is that I need to scroll lengthwise and breathwise to see the content, what I want is the entire website to fit the screen with the letters minimized and not to scroll lengthwise or breadthwise.
below is the code I use:
-(void)viewDidLoad
{
[super viewDidLoad];
self.title=#"MainSite";
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
self.urlAddress4 = #"http://www.livingwaterscf.org/";
self.url4 = [NSURL URLWithString:urlAddress4];
self.requestObj4 = [NSURLRequest requestWithURL:url4];
NSURLConnection *connection=[[[NSURLConnection alloc] initWithRequest:self.requestObj4 delegate:self]autorelease];
[webViewGive loadRequest:requestObj4];
//[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
-(void)webViewDidStartLoad:(UIWebView *)webView
{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}
Set property scalesPageToFit to YES on your web view and your done!
Like:
webViewGive.scalesPageToFit=YES;
You probably want this :
webView.scalesPageToFit = YES;
Is this code correct to use with the networkActivityIndicatorVisible?
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
UIApplication* app2 = [UIApplication sharedApplication];
app2.networkActivityIndicatorVisible = YES;
[self loadSources]; // Loads data in table view
app2.networkActivityIndicatorVisible = NO;
}
Teo
Since NetworkActivityIndicatorVisible can be set from several points while a connection is still active, you need to track the number of calls that enable/disable it. The following UIApplication category does just that using a static variable:
// file UIApplication+NetworkActivity.h
#interface UIApplication (NetworkActivity)
- (void)showNetworkActivityIndicator;
- (void)hideNetworkActivityIndicator;
#end
// file UIApplication+NetworkActivity.m
#import "UIApplication+NetworkActivity.h"
static NSInteger activityCount = 0;
#implementation UIApplication (NetworkActivity)
- (void)showNetworkActivityIndicator {
if ([[UIApplication sharedApplication] isStatusBarHidden]) return;
#synchronized ([UIApplication sharedApplication]) {
if (activityCount == 0) {
[self setNetworkActivityIndicatorVisible:YES];
}
activityCount++;
}
}
- (void)hideNetworkActivityIndicator {
if ([[UIApplication sharedApplication] isStatusBarHidden]) return;
#synchronized ([UIApplication sharedApplication]) {
activityCount--;
if (activityCount <= 0) {
[self setNetworkActivityIndicatorVisible:NO];
activityCount=0;
}
}
}
#end
Now import UIApplication+NetworkActivity.h in your client code and call
// on connection started:
[[UIApplication sharedApplication] showNetworkActivityIndicator];
// on connection finished:
[[UIApplication sharedApplication] hideNetworkActivityIndicator];
If your concern is that the indicator blinks for only a second, you don't need a background process. Just call [self performSelector:#selector(loadSources) withObject:Nil afterDelay:0.1] so the UI thread has time to start the network indicator animation before you block the main thread.
If you're not using AFNetworking (https://github.com/AFNetworking/AFNetworking) already you can check out their network activity indicator implementation in AFNetworkingActivityIndicatorManager.
If you do choose to use this library for your network access, they handle the network activity indicator for you automatically. All you need to do is make one call in your AppDelegate to set it up, they do the rest of the work for you.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES];
}
An shorter solution for tracking multiple activities - again using a UIApplication category and a static variable:
#interface UIApplication (NetworkActivityIndicator)
- (void)toggleNetworkActivityIndicatorVisible:(BOOL)visible;
#end
#implementation UIApplication (NetworkActivityIndicator)
-(void)toggleNetworkActivityIndicatorVisible:(BOOL)visible {
static int activityCount = 0;
#synchronized (self) {
visible ? activityCount++ : activityCount--;
self.networkActivityIndicatorVisible = activityCount > 0;
}
}
#end
I finally solved it. I used performSelectorInBackground to execute the load data into tableView
-(void)beginLoadSources {
[self loadSources]; // Loads data in table view
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self performSelectorInBackground:#selector(beginLoadSources) withObject:nil];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}
Use thins code in your ExempleUIWebView.m
before - (void)viewDidLoad
(void)webViewDidFinishLoad:(UIWebView *)webView {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[ProgressHUD dismiss];
}
and use this after - (void)viewDidLoad
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[ProgressHUD show:#"Loading Privacy Policy" Interaction:NO];