NSNotification for Mission Control - cocoa

Is it possible to receive a notification in a Cocoa app for when Mission Control is launched?
I tried the following with no success:
- (void)applicationDidFinishLaunching:(NSNotification *)notification {
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(notify:) name:NSWorkspaceActiveSpaceDidChangeNotification object:nil];
}
- (void)notify:(NSNotification *)notifcation {
NSLog(#"mission control called");
}

Related

iOS8 : When Keyboard appear and press Back button, at that time next view appear very slow

I have ViewController (v2) with the UITextView . I pushed that view from the viewController (V1).
On V2 When I tap on textview and keyboard appear after that tap on back button and move on V1.
I repeat this process 15 to 20 time and notice that my app's performance become very slow.
Issue is Keyboard take long time to disappear when I tap on Back button :
I am using following line of code :
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(willShowKeyboard:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
}
- (IBAction)back:(id)sender
{
[self.navigationController popViewControllerAnimated:NO];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[noteView becomeFirstResponder];
}
- (void)viewWillDisappear:(BOOL)animated {
[noteView resignFirstResponder];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidHideNotification object:nil];
[super viewWillDisappear:animated];
}
- (void)willShowKeyboard:(NSNotification *)notification
{
[UIView setAnimationsEnabled:NO];
}
- (void)keyboardWillHide:(NSNotification *)notification
{
[UIView setAnimationsEnabled:NO];
}
- (void)keyboardDidHide:(NSNotification *)notification
{
[UIView setAnimationsEnabled:NO];
}
It is simple one line code to dismiss keyboard when user press back button
- (IBAction)back:(id)sender
{
[self.view endEditing:YES];
[self.navigationController popViewControllerAnimated:NO];
}

Is there a change to the behaviour of UIKeyboardWillShowNotification in iOS 8?

I have had a simple UIView block animation that handles animating a group of text fields into view when the keyboard will show (and animate them back when the keyboard hides). This has worked fine in iOS 6 & 7, but now I'm getting incorrect behavior, and it all points to some change in UIKeyboardWillShowNotification.
I set up an isolated project to test this further on a single text field, with two buttons that call exactly the same methods that are fired for the keyboard's WillShow and WillHide notifications. See the results in this video:
Video example
This seems like a bug to me, or it might be a change to the behavior of this notification. Does anyone know if this is intended and/or what can be done about it?
Here is the relevant code:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
- (void)keyboardWillShow:(NSNotification *)notification
{
[UIView animateWithDuration:0.3 animations:^{
self.textField.frame = CGRectOffset(self.textField.frame, 0.f, _destY - _origY);
}];
}
- (void)keyboardWillHide:(NSNotification *)notification
{
[UIView animateWithDuration:0.3 animations:^{
self.textField.frame = CGRectOffset(self.textField.frame, 0.f, _origY - _destY);
}];
}

How do I detect QTMovie stop playing?

I have done the following - once played a QTMovie (on Mountain Lion) and wanted to get notification when a movie ended. But the notification never got called! Can anybody tell me what have I done wrong?
- (void)playMovie:(QTMovie *)movie {
[self.movieView.movie stop];
if (movie) {
self.movieView.movie = movie;
[movie gotoBeginning];
[movie play];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(stopMovie:) name:QTMovieDidEndNotification object:self];
}
}
- (void)stopMovie:(NSNotification *)notification {
NSLog(#"stop movie!");
[[NSNotificationCenter defaultCenter] removeObserver:self name:QTMovieDidEndNotification object:nil];
}
Try changing to the following (note the object parameter):
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(stopMovie:)
name:QTMovieDidEndNotification
object:movie];

How to disable MasterView when the keyboard appears in the DetailView

I would like to know if it's possible (and how) when the keyboard appears in the DetailView, to disable any MasterView controls until it disappears. All of this happens in a split view based app of course.
---Update for Prince's solution---
MasterViewController.h
#property (strong, nonatomic) UIView *MasterView;
MasterViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
MasterView=self.view;
self.detailViewController = (DetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
self.detailViewController = (DetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
}
DetailViewController.m
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
((MasterViewController *)self.parentViewController).MasterView.userInteractionEnabled=NO;
return YES;
}
This code as is, crashes the app with an "Unknown Selector" error.
How do i bind delegates; Don't know if that's the problem or not. Any help?
Use UITextField's delegate and also bind delegates:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
MasterView.userInteractionEnabled = NO;
.......
return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
MasterView.userInteractionEnabled = YES;
[textField resignFirstResponder];
return YES;
}
I found out a solution!
in MasterView viewDidLoad:
//---registers the notifications for keyboard---
// to see if keyboard is shown / not shown
[[NSNotificationCenter defaultCenter]
addObserver: self
selector:#selector(keyboardDidShow:)
name:UIKeyboardDidShowNotification
object:self.view.window];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(keyboardDidHide:)
name:UIKeyboardDidHideNotification
object:nil];
and then...:
//----------Handling Keyboard Appearence---
-(void) keyboardDidShow:(NSNotification *) notification {
[self.tableView setUserInteractionEnabled:NO];
}
//---when the keyboard disappears---
-(void) keyboardDidHide:(NSNotification *) notification {
[self.tableView setUserInteractionEnabled:YES];
}
//---before the View window disappear---
-(void) viewWillDisappear:(BOOL)animated {
//---removes the notifications for keyboard---
[[NSNotificationCenter defaultCenter]
removeObserver: self
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:UIKeyboardWillHideNotification
object:nil];
}

Drawing NSControl when the windows is key or not

I have a NSControl subview and I want to change the drawing when the control is not on a keyWindow. The problem is that I don't see any property that reflects that state (tried enabled property but that was not it).
In simple terms, can I differentiate between these two states?
You can use NSWindow's keyWindow property, and if you want to check to see if your control is the first responder for keyboard events also test [[self window] firstResponder] == self. I don't believe keyWindow supports KVO, but there is a NSWindowDidBecomeKeyNotification and NSWindowDidResignKeyNotification you can listen for. For instance,
- (id)initWithFrame:(NSRect)frameRect;
{
if ( self = [super initWithFrame:frameRect] )
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(display) name:NSWindowDidResignKeyNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(display) name:NSWindowDidBecomeKeyNotification object:nil];
}
return self;
}
- (void)drawRect:(NSRect)aRect;
{
if ( [[self window] isKeyWindow] )
{
// one way...
}
else
{
// another way!
}
}
- (void)dealloc;
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSWindowDidResignKeyNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSWindowDidBecomeKeyNotification object:nil];
[super dealloc];
}

Resources