Is it possible to make a background ViewController unclickable? - ios

So I've got a UIActivityViewController that takes up half the screen when my app runs, what happens is when I click the half it doesn't take up then it'll disappear and my original blank ViewController appears.
Is it possible to permanently keep the UIActivityView up until the user clicks on one of the sharing options (such as Facebook, or Mail)? Otherwise I'll just work around it.
I load the ActivityView with:
-(void)viewDidAppear:(BOOL)animated{
UIActivityViewController *controller = [[UIActivityViewController alloc]initWithActivityItems:#[#""] applicationActivities:nil];
[self presentViewController:controller animated:YES completion:nil];
}

Yes, it is possible, you can try something like
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(showAViewController) name:#"showAViewController" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(dissmissAViewController) name:#"dissmissAViewController" object:nil];
}
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter]removeObserver:self name:#"showAViewController" object:nil];
[[NSNotificationCenter defaultCenter]removeObserver:self name:#"dissmissAViewController" object:nil];
}
-(void)showAViewController{
self.view.userInteractionEnabled=NO;
}
-(void)dissmissAViewController{
self.view.userInteractionEnabled=YES;
}
When you are showing a view controller on top of another view controller just call
[[NSNotificationCenter defaultCenter] postNotificationName:#"showAViewController" object:nil];
After you dismiss it or remove it, just call:-
[[NSNotificationCenter defaultCenter] postNotificationName:#"dissmissAViewController" object:nil];

Related

iOS 9.0 - getting keyboard will show/hide notifications from other apps

My view controller registers to keyboard notifications (keyboardWillShow, keyboardWillHide).
I launch my app. It is showing the viewcontroller that is registered to keyboard notifications. The keyboard is not visible.
I switch to the sms app and start writing text. While I'm writing, my app gets a notification. The notification is displayed as a banner on the top of the screen.
When I click the banner, my app is opened and immediately gets a keyboard notification.
As far as I can tell, this keyboard notification is related to the keyboard of the SMS.
How do I identify if the keyboard event came from my app or not?
you can remove listening to observers (keyboard notifications) in viewWillDisappear and can start listening to observer again in viewWillAppear, this might solve the problem
- (void)registerForKeyboardNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWasShown:)
name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(applicationWillEnterBackground:)
name:UIApplicationWillResignActiveNotification
object:nil];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillDisappear:animated];
[self registerForKeyboardNotifications];
}
- (void)deregisterForKeyboardNotifications {
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[center removeObserver:self name:UIKeyboardWillHideNotification object:nil];
[center removeObserver:self name:UIApplicationWillResignActiveNotification object:nil];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self deregisterForKeyboardNotifications];
}

Start function from popover view controller

I have main viewcontroller that opens via popover segue other view controller with buttons.
On button click what I wish to happen is function from first viewcontroller fire and the popover will close. How do I do so properly?
On settings button click the popover open. Then when user click Manual Content Update the the view will close and start function on Projects Main viewController.
You can use NSNotificationCenter.
In your main UIViewController add:
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(receivePopoverNotification:)
name:#"PopoverNotification"
object:nil];
}
-(void) dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void) receivePopoverNotification:(NSNotification *) notification
{
[self.popover dismissPopoverAnimated: YES];
self.popover = nil;
}
In your UIPopoverController add:
-(IBAction) pressButton: (id) sender {
[[NSNotificationCenter defaultCenter]
postNotificationName:#"PopoverNotification"
object:nil];
}

remove AppDelegate's observer in other ViewController

The NSNotification observer is in didFinishLaunchingWithOptions
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(newShipCome:) name:kNewShipNotifaction object:nil];
I would like to remove observer in another ViewController.
I've done this in one of my ViewController
[[NSNotificationCenter defaultCenter] removeObserver:[UIApplication sharedApplication] name:kNewShipNotifaction object:nil];
but still not work. Do anyone know how to do this?
thanks
You need to remove observer of AppDelegate, you are passing incorrect object in removeObserver: method.
Instead of :
[[NSNotificationCenter defaultCenter] removeObserver:[UIApplication sharedApplication] name:kNewShipNotifaction object:nil];
Use:
[[NSNotificationCenter defaultCenter] removeObserver:[[UIApplication sharedApplication] delegate] name:kNewShipNotifaction object:nil];

UIKeyboardWillShowNotification doesnt work from iOS > 6.1

Init section:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification object:nil];
Some method:
- (void) keyboardWillShow:(NSNotification*) aNotification {
// TO DO
}
Dealloc section:
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
So keyboardWillShow is not called after presenting view in iOS 6.1...
In iOS 6.0 this code works perfectly.
In which "init section" are the observers being added? If your view controller is from a storyboard, for example, then it should be in - (id)initWithCoder:(NSCoder *)decoder.
My recommendation, however, is to set up the observers in viewWillAppear and remove them in viewWillDisappear. That way the setup and tear down are "balanced" and only active when the view controller's content is visible.

Disable a button when the keyboard is popped up

I got a UITextField, when you click on it there pops up a keyboard. I've added the UITextField using storyboard and now I want to disable a button when the keyboard pops up. How can I do this?
For disabling the button: [self.howButton setEnabled:NO];
But where do I put this?
you can add your keyboards stament to the notifacticon , when it show , then disable the button , when it hide , then enable the button
in the init to add the observer
- (void)init
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillHide) name:UIKeyboardWillHideNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillShow) name:UIKeyboardWillShowNotification object:nil];
}
achieve the show and hide method
- (void)keyboardWillHide
{
[self.howButton setEnabled:YES];
}
- (void)keyboardWillShow
{
[self.howButton setEnabled:NO];
}
finally remove the observer , when the class is dealloc
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
Register for UIKeyboardWillShowNotification
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillShow) name:UIKeyboardWillShowNotification object:nil];
In the keyboardWillShow method disable your button.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillHide) name:UIKeyboardWillHideNotification object:nil];
You can re-enable the button if required by registering for the above notification.

Resources