nsnotificationcenter

Move view with keyboard using Swift

烈酒焚心 提交于 2019-12-16 22:06:34
问题 I have an app that has a text field on the lower half of the view. This means that when I go to type in the text field the keyboard covers the textfield. How would I go about moving the view upwards while typing so I can see what i'm typing and then moving it back down to its original place when the keyboard disappears? I've looked everywhere but all the solutions appear to be in Obj-C which I can't quite convert just yet. Any help would be greatly appreciated. 回答1: Here is a solution,

Is it possible to update something in the UI while performing synchronous calls or other operations?

ぐ巨炮叔叔 提交于 2019-12-13 21:01:02
问题 At several points in my project, I need to perform some synchronous web service calls or read from CoreData. It may take a couple seconds to preform these operations, so I created a LoadingView class that is a subclass of UIView that has a simple message and a UIActivityIndicatorView . For normal UIButton s, I just [myLoadingView setHidden:NO] on the Touch Down event, and [myLoadingView setHidden:YES] on the Touch Up Inside event. This all works exactly how I want. The problem is I cannot

Warning for iOS/iPhone users about duplicate NSNotification observations

江枫思渺然 提交于 2019-12-13 12:23:42
问题 This isn't a question so much as a warning to others to save them some time. NSNotificationCenter on iOS 3/iPhone OS 3 (I'm assuming also Mac OS X and iOS 4) has the following behavior: If you register yourself multiple times for the exact specific notification, NSNotificationCenter will NOT recognize the redundancy and instead will fire off as many notifications to you as you've registered an observation for. This is almost never the behavior you want to see and is almost always accidental.

KVO versus NSNotifications [duplicate]

杀马特。学长 韩版系。学妹 提交于 2019-12-13 11:57:41
问题 This question already has an answer here : NSNotification VS KVO (1 answer) Closed 5 years ago . Is there any advantage to use KVO instead of the more "generic" (and to my opion more robust) feature of NSNotification s ? 回答1: I hate KVO with passion, mainly because it forces me to route all KVO notifications through a single handler. I use whatever else available if I have the choice. But KVO has the distinct advantage of being available for many of the classes in the standard library – if

Observing Notification in Today Widget which is posted from main app

天大地大妈咪最大 提交于 2019-12-13 03:58:44
问题 I have declared notification name in a swift file which has target membership of both main app and today widget: let SpecialKey = Notification.Name("howLongNotif") Then in my main app view controller, I am posting notification when location is updated (background mode for location updates is on): NotificationCenter.default.post(name: SpecialKey, object: nil, userInfo: nil) In my today widget viewDidLoad, I am observing it like this: NotificationCenter.default.addObserver(self, selector:

_UIImagePickerControllerUserDidCaptureItem not called xcode 6

十年热恋 提交于 2019-12-13 01:26:18
问题 Is it just me or _UIImagePickerControllerUserDidCaptureItem notification from uiimagepickercontroller stopped working on iOS 8 and XCode 6. I use it to rotate the camera overlay after the user taked a picture. PLease help 回答1: It's pretty strange, but in iOS 8 setting observer using [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(imagePickerControllerDidCapture) name:@"_UIImagePickerControllerUserDidCaptureItem" object:nil]; doesn't work for UIImagePickerController,

Handle UILocalNotification in UIViewController using NSNotification after the app has been terminated

有些话、适合烂在心里 提交于 2019-12-13 00:04:52
问题 I'm working with UILocalNotification and I would like to notify one of my controller that the notification has been received even if the app has been terminated. In my appDelegate I implemented this function: -(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { if ([application applicationState] == UIApplicationStateInactive) { [[NSNotificationCenter defaultCenter] postNotificationName:@"localNotificationReceived" object

Is removing observer obligatory (necessary)?

梦想与她 提交于 2019-12-12 17:24:44
问题 There is an observer that I need it in all of app life cycle, shall I ever remove it? I think GC will remove it after app is closed, am I right? If yes, then when shall I remove it? in deinit ? 回答1: If you are providing support to iOS 8 and before. You will have to remove the observer inside dealloc or viewWillDisappear . A more detailed answer can be found here. If you are providing support from iOS 9 onwards, it is no longer necessary to manually remove the observer. From apple docs: In OS

The right place to call .removeObserver for NSNotificationCenter = Swift deinit()?

只愿长相守 提交于 2019-12-12 10:34:22
问题 I've read a lot of suggestions for the right place to call .removeObserver for NSNotificationCenter since viewDidUnload is not an option. I was just wondering if the new deinit() in Swift would be a good choice? -nick 回答1: It really depends on the role of the class where you subscribe to NSNotificationCenter notifications. If you are subscribing in: UIView Then you should unsubscribe as soon as view gets invisible to the user. To save CPU cycles and not consume resources while user does not

Pausing iOS game when Notification Center/Control Center is launched

白昼怎懂夜的黑 提交于 2019-12-12 09:27:40
问题 I’m assuming my app is sent notifications through NSNotificationCenter when these kind of events happen. Does anyone know what these are? 回答1: In the app I'm working on I needed to handle these events as well and did so using the following two notifications: UIApplicationWillResignActiveNotification >> This notification is fired when the Notification Center or Control Center is brought up. UIApplicationWillEnterForegroundNotification >> This notification is fired when the Notification Center