考虑键盘的新QuickType部分.
为这件事千真万确可以使用只有一个通知UIKeyboardWillChangeFrameNotification,
并且只是"不打扰""旧"UIKeyboardWillShowNotification和UIKeyboardWillHideNotification?
测试似乎表明它完美运行,仅使用keyboardFrameDidChange - 但我们可能会遗漏一些东西?
BTW这里是一个如何使用UIKeyboardWillChangeFrameNotification的例子 /sf/answers/1835871271/
我创建了一个扩展名,Notification.Name如下所示:
public extension Notification.Name {
public static let blahblahblah = Notification.Name(rawValue: "blahblahblah")
Run Code Online (Sandbox Code Playgroud)
}
现在我想在Objective-C中使用这个扩展,但即使它是公共的也无法访问.
你能告诉我如何在Objective-C和Swift中访问和使用这个swift扩展吗?
以前我在Objective-C中使用常量值,但现在为了升级我的代码,我想使用这个扩展.
我想知道是否有理由在KVO和NSNotificationCenter观察中使用一个而不是另一个.性能,内存使用,速度等?
cocoa binding key-value-observing nsnotification nsnotificationcenter
我正在尝试子类NSNotification.
Apple的文档NSNotification陈述如下:
NSNotification是一个没有实例变量的类集群.因此,你必须继承NSNotification和覆盖原始的方法name,object和userInfo.您可以选择任何您喜欢的指定初始值设定项,但请确保您的初始化程序不会调用 (via )NSNotification的实现. 并不意味着直接实例化,它的 方法引发了异常.init[super init]NSNotificationinit
但这对我来说并不清楚.我应该创建这样的初始化器吗?
-(id)initWithObject:(id)object
{
return self;
}
Run Code Online (Sandbox Code Playgroud) 使用的黄金法则NSNotification似乎是
"
removeObserver在observer(或object)之前的呼叫被解除分配".
我正在处理一个没有遵循此规则的代码库,但我无法找到违规行为.我搜索了代码并确保每个addObserver都有匹配removeObserver但我仍然看到以下变化的崩溃报告:
OS Version: iPhone OS 5.0.1 (9A405)
Report Version: 104
Exception Type: SIGSEGV
Exception Codes: SEGV_ACCERR at 0x8
Crashed Thread: 0
Thread 0 Crashed:
0 libobjc.A.dylib 0x31516fbc objc_msgSend + 16
1 Foundation 0x3195b50f __57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke_0 + 19
2 CoreFoundation 0x37a02577 ___CFXNotificationPost_block_invoke_0 + 71
3 CoreFoundation 0x3798e0cf _CFXNotificationPost + 1407
4 Foundation 0x318cf3fb -[NSNotificationCenter postNotificationName:object:userInfo:] + 67
5 UIKit 0x34e5ee25 -[UIApplication _handleApplicationSuspend:eventInfo:] + 697
6 UIKit 0x34deed17 …Run Code Online (Sandbox Code Playgroud) cocoa-touch objective-c crash-reports nsnotification nsnotificationcenter
我有一个带有此NSNotification的UITextField:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldDidChange:) name:@"UITextFieldTextDidChangeNotification" object:_searchTextField];
- (void)textFieldDidChange :(NSNotification *)notif
{
//
}
Run Code Online (Sandbox Code Playgroud)
当我输入时,NSLog就是 r
NSConcreteNotification 0x193c20 {name = UITextFieldTextDidChangeNotification; object = <UITextField: 0x15a980; frame = (20 20; 280 31); text = 'r'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x15aad0>>}
Run Code Online (Sandbox Code Playgroud)
如何r从notif对象中获取文本?
iphone objective-c uitextfield nsnotification nsnotificationcenter
我可能没有把我的头衔措辞得很好,也许更正确的说我的NSNotification并没有在完成比赛后放弃我的电影观点.我发现其他人有这个问题,但没有解决方案,似乎它可能是iOS 6的问题,这就是我正在运行的.
视频完成播放后,您需要按"完成"才能解除,但我希望它能自动关闭,因为我将使用MPMovieControlStyleNone一旦我将其整理出来.这是我的代码,未使用的部分被删除:`
#import "MovieViewController.h"
@interface MovieViewController ()
@end
@implementation MovieViewController
@synthesize moviePlayer = _moviePlayer;
- (IBAction)playMovie:(id)sender
{
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:@"TestMovie" ofType:@"mov"]];
_moviePlayer =
[[MPMoviePlayerController alloc]
initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:_moviePlayer];
_moviePlayer.controlStyle = MPMovieControlStyleDefault;
_moviePlayer.shouldAutoplay = YES;
[self.view addSubview:_moviePlayer.view];
[_moviePlayer setFullscreen:YES animated:NO];
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification {
MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
if ([player
respondsToSelector:@selector(setFullscreen:animated:)])
{
[player.view removeFromSuperview];
}
}
@end`
Run Code Online (Sandbox Code Playgroud) 我正在使用MPMoviePlayerController,如何检测电影实际开始播放的时间 - 而不是当用户摆弄搜索控件时?
从我做的测试中,我总是得到一个"加载状态改变"事件,并且(moviePlayer.loadState == MPMovieLoadStatePlayable)就TRUE在电影开始时和用户拖动搜索控件之后(即使他将它从一端拖到中间 - 不一定是电影的开头) .如何区分电影启动和搜索?
mpmovieplayercontroller seek nsnotification nsnotificationcenter ios
我正在动态地在一堆tableview控制器上注册一个观察者,所以如果他们在同一个对象上注册,我需要删除以前的观察者.为此,我需要检查对象上是否存在观察者.
这可能吗?我知道使用NSNotification你可以使用NSNotification中心单例,但这对于KVO是一样的吗?
iphone key-value-observing nsnotification nsnotificationcenter ios
我有一个类似你可以在下面看到的UIView:
class ViewTaskViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
subscribeToNotifications()
}
func subscribeToNotifications() {
let notification = NotificationCenter.default
notification.addObserver(forName: Notification.Name(rawValue: "TimerUpdated"), object: nil, queue: nil, using: handleUpdateTimer)
print("Subscribed to NotificationCenter in ViewTaskViewController")
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
print("TUFU TUFU TUFU")
NotificationCenter.default.removeObserver(self)
}
deinit {
print("DENINT")
}
@objc func handleUpdateTimer(notification: Notification) {
if let userInfo = notification.userInfo, let timeInSeconds = userInfo["timeInSeconds"] as? Int {
withUnsafePointer(to: &self.view) {
print("We got timeeeeee \(timeInSeconds) \($0)")
}
//do something …Run Code Online (Sandbox Code Playgroud) nsnotification ×10
ios ×4
objective-c ×3
cocoa ×2
iphone ×2
binding ×1
cocoa-touch ×1
deinit ×1
inheritance ×1
ios6 ×1
ios8 ×1
memory-leaks ×1
movie ×1
seek ×1
swift ×1
swift3 ×1
uikeyboard ×1
uitextfield ×1
video ×1