NSNotification相关

本文详细介绍了NSNotification的使用方法,包括如何通过addObserver方法注册观察者、指定观察者响应的方法及条件,以及如何通过postNotificationName方法发布通知。同时,还提供了具体的代码示例,帮助读者更好地理解和应用NSNotification。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

addObserver:selector:name:object:

Adds an entry to the receiver’s dispatch table with an observer, a notification selector and optional criteria: notification name and sender.

- (void)addObserver:(id) notificationObserver selector:(SEL) notificationSelector name:( NSString *) notificationNameobject:(id) notificationSender
Parameters
notificationObserver

Object registering as an observer. This value must not be nil.

指定观察者是谁,此参数不能为空,一般为self

notificationSelector

Selector that specifies the message the receiver sends notificationObserver to notify it of the notification posting. The method specified by notificationSelector must have one and only one argument (an instance of NSNotification).

观察者要响应的方法,此方法必须要有而且只有一个参数'NSNotification'

notificationName

The name of the notification for which to register the observer; that is, only notifications with this name are delivered to the observer.

If you pass nil, the notification center doesn’t use a notification’s name to decide whether to deliver it to the observer.

通知的名称,在通知中心注册的名字


notificationSender

The object whose notifications the observer wants to receive; that is, only notifications sent by this sender are delivered to the observer.

If you pass nil, the notification center doesn’t use a notification’s sender to decide whether to deliver it to the observer.

谁发送的这个通知



postNotificationName:object:userInfo:

Creates a notification with a given name, sender, and information and posts it to the receiver.

- (void)postNotificationName:( NSString *) notificationName object:(id) notificationSender userInfo:( NSDictionary*) userInfo
Parameters
notificationName

The name of the notification.

notificationSender

The object posting the notification.

userInfo

Information about the the notification. May be nil.

   通知中心的内容


//点击按钮

- (IBAction)btnPressed:(id)sender

{

    [[NSNotificationCenter defaultCenter] postNotificationName:@"hello" object:nil userInfo:[NSDictionary dictionaryWithObject:@"YES" forKey:@"result"]];

}

//注册通知

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hello:) name:@"hello" object:nil];


//响应通知

- (void)hello:(NSNotification *)sender

{

    NSDictionary *dict = [sender userInfo];

    NSString *str = [dict objectForKey:@"result"];

    NSLog(@"str = %@",str);

}


//NSNotification的使用

@interface NSNotification : NSObject <NSCopying, NSCoding>


- (NSString *)name;

- (id)object;

- (NSDictionary *)userInfo;


@end





资源下载链接为: https://pan.quark.cn/s/67c535f75d4c 在Android开发中,为了提升用户体验和视觉效果,背景模糊化处理是一种常用的设计手段。它可以为应用界面增添层次感,同时突出显示主要内容。本文将详细介绍如何在Android中实现背景模糊化功能。 首先,我们需要获取当前设备的壁纸作为背景。这可以通过WallpaperManager类来完成。调用WallpaperManager.getInstance(this.getContext())可以获取壁纸管理器实例,然后通过getDrawable()方法获取当前壁纸的Drawable对象。接下来,需要将壁纸Drawable转换为Bitmap对象,因为模糊处理通常需要在Bitmap上进行。可以通过((BitmapDrawable) wallpaperDrawable).getBitmap()来完成这一转换。 模糊处理的核心是使用Android的RenderScript API。RenderScript是一种高效的并行计算框架,特别适合处理图像操作。在blur()方法中,我们创建了一个RenderScript实例,并利用ScriptIntrinsicBlur类来实现模糊效果。ScriptIntrinsicBlur提供了设置模糊半径(setRadius(radius))和执行模糊操作(forEach(output))的方法。模糊半径radius可以根据需求调整,以达到期望的模糊程度。 然而,仅依赖ScriptIntrinsicBlur可能无法达到理想的模糊效果,因此我们还需要对原始图片进行缩放处理。为此,我们设计了small()和big()方法。先将图片缩小(small()),然后执行模糊操作,最后再将图片放大(big())。这种方式不仅可以增强模糊效果,还能在一定程度上提高处理速度。在small(
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值