首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏正则

    AFNetworking源码探究(十九) —— UIKit相关之几个分类

    object:nil]; [notificationCenter removeObserver:self name:AFNetworkingTaskDidSuspendNotification object:nil]; [notificationCenter removeObserver:self name:AFNetworkingTaskDidCompleteNotification object:nil]; [notificationCenter removeObserver:self name:AFNetworkingTaskDidResumeNotification object:nil]; [notificationCenter removeObserver:self name:AFNetworkingTaskDidSuspendNotification = [NSNotificationCenter defaultCenter]; // 先移除对上个任务的通知监听 [notificationCenter removeObserver

    61520发布于 2021-09-03
  • 来自专栏正则

    AFNetworking源码探究(二十五) —— UIKit相关之UIRefreshControl+AFNetworking分类

    - (void)setRefreshingWithStateOfTask:(NSURLSessionTask *)task { NSNotificationCenter *notificationCenter object:nil]; [notificationCenter removeObserver:self name:AFNetworkingTaskDidSuspendNotification object:nil]; [notificationCenter removeObserver:self name:AFNetworkingTaskDidCompleteNotification @selector(af_beginRefreshing) name:AFNetworkingTaskDidResumeNotification object:task]; [notificationCenter @selector(af_endRefreshing) name:AFNetworkingTaskDidCompleteNotification object:task]; [notificationCenter

    56150发布于 2021-09-03
  • 来自专栏Unity3d程序开发

    U3D观察者模式,实现1对多

    return string.Format("sender={0},param={1}", this.sender, this.param); } } public class NotificationCenter { ///

    /// 通知中心单例 /// private static NotificationCenter instance = null; public delegate void OnNotification(Notification notific); public static NotificationCenter Get() { if (instance == null) { instance = new NotificationCenter(); ().ObjAddEventListener(KEventKey.m_evChallengeCommit, gameObject, OnEvCommit); NotificationCenter.Get

    33020编辑于 2023-08-24
  • 来自专栏学海无涯

    iOS26适配指南之通知

    通过全新的并发安全通知协议NotificationCenter.MainActorMessage(主线程消息)与NotificationCenter.AsyncMessage(异步消息)可以做到编译时检测 static let shared = NotificationSubject() } // MARK: - 消息类型 public struct CustomMainActorMessage: NotificationCenter.MainActorMessage super.viewDidLoad() view.addSubview(label) // 监听通知 mainActorMessageToken = NotificationCenter.default.addObserver { // 发送通知 NotificationCenter.default.post(CustomMainActorMessage(info: "you have a new message"), subject: NotificationSubject.shared) } deinit { NotificationCenter.default.removeObserver

    48410编辑于 2025-07-05
  • 来自专栏学海无涯

    Combine-Foundation中的Publisher

    timerPublisher.connect() // 可以取消 // subscription.cancel() Notification Publisher 和 Timer 类似,Foundation 中的 NotificationCenter 系统通知 let subscription = NotificationCenter.default.publisher(for: UIApplication.willResignActiveNotification :Notification.Name { return Notification.Name("YungFan") } } // 订阅通知 let subscription = NotificationCenter.default.publisher }) // 创建通知 let noti = Notification(name: .myNotiName, object: "some info", userInfo: nil) // 发送通知 NotificationCenter.default.post var body: some View { Text("") // onReceive捕获通知 .onReceive(NotificationCenter.default.publisher

    1.5K30发布于 2020-03-24
  • 来自专栏码客

    iOS听筒和外放切换

    UIDevice.current.isProximityMonitoringEnabled = true; if(UIDevice.current.isProximityMonitoringEnabled){ NotificationCenter.default.addObserver UIDevice.current.isProximityMonitoringEnabled){ UIDevice.current.isProximityMonitoringEnabled = false; NotificationCenter.default.removeObserver NSNotification.Name.UIDeviceProximityStateDidChange, object: nil); } } @objc func sensorStateChange(_ notification:NotificationCenter

    1.3K10发布于 2019-10-22
  • 来自专栏每日一篇技术文章

    Swift3.0 - 空间命名

    student1 = MyClassContrainer1.Student() let student2 = MyClassContrainer1.Student() 应用场景1: 我们想通知中心发送一条消息 NotificationCenter.default.post (name: Notification.Name("SocketConnectFailure"), object: ["errorCode":000]) 我们注册通知的写法是下面这样的 NotificationCenter.default.addObserver let connectSuccess = Notification.Name(rawValue: "SocketConnectSuccess") } } 使用: // 想通知中心post 消息 NotificationCenter.default.post (name: Notification.Name.SocketTask.connectFailure, object: ["errorCode":000]) // 增加观察者 NotificationCenter.default.addObserver

    41300发布于 2018-09-14
  • 来自专栏肘子的Swift记事本

    用NavigationViewKit增强SwiftUI的导航视图

    print("other back") } } } } }} 使用NotificationCenter 因此NavigationViewManager提供了基于NotificationCenter的类似方法。 : let backToRootItem = NavigationViewManager.BackToRootItem(tag: "nv1", animated: false, action: {})NotificationCenter.default.post 使用NotificationCenter跳转到新视图 在代码中: let pushViewItem = NavigationViewManager.PushViewItem(tag: "nv1", animated (name:.NavigationViewManagerPushView, object: pushViewItem) 通过NotificationCenter跳转视图时,视图需转换为AnyView。

    4.6K20编辑于 2022-07-28
  • 来自专栏学海无涯

    Combine-实践

    sendButton) .store(in: &cancellables) // 通知需要绑定到messageLabel的text NotificationCenter.default.publisher store(in: &cancellables) /* // 上面的写法等于下面3句 let messagePublisher = NotificationCenter.Publisher sender.isOn } @IBAction func buttonClicked(_ sender: UIButton) { // 发送通知 NotificationCenter.default.post

    1.7K10发布于 2020-05-18
  • 来自专栏码生

    Reveal Swift3.0使用

    , 2) command alias swift_reveal_start expr NotificationCenter.default.post(name: NSNotification.Name( rawValue: "IBARevealRequestStart"), object: nil) command alias swift_reveal_stop expr NotificationCenter.default.post

    66620发布于 2018-11-21
  • 来自专栏每日一篇技术文章

    Swift3.0 - 键盘相关

    键盘出现和消失获取键盘的相关信息 注册通知 NotificationCenter.default.addObserver(self, selector: #selector(keyBoardWillShow (notification:)), name: NSNotification.Name.UIKeyboardWillShow, object: nil) NotificationCenter.default.addObserver

    43920发布于 2018-09-14
  • 来自专栏Unity3d程序开发

    unity3d scrollview 滚动层dotween移动到指定位置:例如有10项,滚动到第9项

    ; [SerializeField] float m_cellY; private void Awake() { //以后通知订阅放awake NotificationCenter.Get KEventKey.m_evScrollToItem, gameObject, OnEventScroll); } private void OnDestroy() { NotificationCenter.Get

    97430编辑于 2023-08-24
  • 来自专栏小丑的小屋

    这一次,彻底弄懂 JavaScript 函数执行机制

    五、react 函数式组件中的闭包 const [value, setValue] = useState([]); useEffect(() => { notificationCenter.on (EVENT_NAME, eventListener); return () => { notificationCenter.off(EVENT_NAME, eventListener ); return () => { notificationCenter.off(EVENT_NAME, eventListener); }; }, [value]); const valueRef = useRef([]); useEffect(() => { notificationCenter.on(EVENT_NAME, eventListener); return () => { notificationCenter.off(EVENT_NAME, eventListener); }; }, []); function

    1.3K10发布于 2021-05-18
  • 来自专栏家劲

    iOS 开发之路(登陆页键盘遮挡输入框问题)一

          在学习开发登陆页的时候,遇到的问题分享如下:     首先是swift 3.0 中,NotificationCenter 设置 selector 如下: @IBOutlet weak var storyboard对最底部的控件设置约束,然后连线到.swift文件进行绑定   override func viewDidLoad() { super.viewDidLoad() NotificationCenter.default.addObserver

    1.1K30发布于 2019-09-19
  • 来自专栏Swift社区

    苹果仍在研发更大尺寸的 iMac | Swift 周报 issue 60

    然而,目前的 NotificationCenter 存在一些问题。首先,通知的并发性依赖于隐式约定,观察者的代码块通常会在与发布者相同的线程上运行。 为了解决这些问题,提案提出了一个新协议 NotificationCenter.Message,该协议允许创建可以通过 NotificationCenter 发布和观察的类型,并提供对 Swift 并发的支持 通过定义 Notification.Name,NotificationCenter.Message 可以与现有的 Notification 类型兼容。 默认情况下,符合 NotificationCenter.Message 的类型的观察者将在 MainActor 上运行,并且可以指定其他的隔离上下文。 提案还介绍了如何在 NotificationCenter.Message 与现有的 Notification 类型之间进行转换,例如通过定义 makeMessage(_:) 方法将通知转换为 NotificationCenter.Message

    2.2K11编辑于 2024-09-17
  • 来自专栏肘子的Swift记事本

    聊聊 Combine 和 async/await 之间的合作

    当一个属性发生变化,一个用户点击了按钮,或者通过 NotificationCenter 发送了一个通知,开发者都可以通过 Combine 提供了的内置工具做出及时处理。 如果我们只通过 NotificationCenter 来发送事件,下面的代码就直接可以满足我们的需求: let n = Notification.Name("event") Task { for await value in NotificationCenter.default.notifications(named: n, object: nil) { if let str String { await asyncPrint(value: str) } } } NotificationCenter.default.post( name: n, object: "event1") NotificationCenter.default.post(name: n, object: "event2") NotificationCenter.default.post

    1.2K30编辑于 2022-07-28
  • 来自专栏学海无涯

    SwiftUI监听ViewModel变化

    Timer.scheduledTimer( withTimeInterval: 2.0, repeats: true, block: { _ in NotificationCenter.default.post self.randomColor() }) // 收到通知 changeSizeMessageObserver = NotificationCenter.default.addObserver } } deinit { // 移除通知 if let obs = changeSizeMessageObserver { NotificationCenter.default.removeObserver

    83911编辑于 2024-03-10
  • 来自专栏音视频技术学习笔记

    音视频技术(3)- 入门DEMO

    moviePlayer.view]; } return _moviePlayer; } -(void)addNotification{ NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; [notificationCenter addObserver:self selector:@selector( mediaPlayerPlaybackStateChange:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:self.moviePlayer]; [notificationCenter

    1.2K20发布于 2020-03-27
  • 来自专栏肘子的Swift记事本

    Swift 的多平台策略,需要我们大家一起来建设 | 肘子的 Swift 周报 #091

    原创 NotificationCenter.Message:Swift 6.2 并发安全通知的全新体验[6] NotificationCenter 作为 iOS 开发中的经典组件,为开发者提供了灵活的广播 为了彻底解决这些痛点,Swift 6.2 在 Foundation 中引入了全新的并发安全通知协议:NotificationCenter.MainActorMessage和 NotificationCenter.AsyncMessage https://www.swift.org/android-workgroup/ [5] Swift Package Index: https://swiftpackageindex.com [6] NotificationCenter.Message

    39400编辑于 2025-07-01
  • 来自专栏学海无涯

    Combine-常见使用场景

    self = self else { return } self.countLbl.text = count.format }) 通知 借助 NotificationCenter private var subscriptions = Set<AnyCancellable>() NotificationCenter .default

    59910编辑于 2025-05-23
领券