zoukankan      html  css  js  c++  java
  • 有关通知的简单使用

       //发送通知
        NSNotification *updateNotifi = [NSNotification notificationWithName:notification_name_update_push object:nil];
        [[NSNotificationCenter defaultCenter] postNotification:updateNotifi];
     
     
     
     
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addFavWork) name:@"add_stylist_work" object:nil];
     
     
    -(void)addFavWork{
        //没有收藏,则收藏
        AppStatus *as = [AppStatus sharedInstance];
        if([as.user hasAddFavWork:self.work.id]){
            self.collectImage.image = hasAddWork;
        }else{
            isOperateWork = YES;
            [[UserStore sharedStore] addFavWork:^(NSError *err) {
                if (err == nil) {
                    [[StylistWorkStore sharedStore] getStylistWorkList:^(Page *page, NSError *err) {
                        isOperateWork = NO;
                        [SVProgressHUD showSuccessWithStatus:@"收藏成功!" duration:1.0];
                        self.collectImage.image = hasAddWork;
                        self.numOfCollect.text = [NSString stringWithFormat:@"   有%d个用户收藏了该作品",++self.work.collectedCount];
                        [[NSNotificationCenter defaultCenter] postNotificationName:@"operate_work" object:nil];
                        [MobClick event:log_event_name_add_fav_work attributes:[NSDictionary dictionaryWithObjectsAndKeys:@(self.work.stylist.id), @"作品", nil]];
                    } url:as.user.idStr refresh:YES];
                }else{
                    [SVProgressHUD showErrorWithStatus:@"收藏失败,请稍后再试!" duration:1.0];
                    isOperateWork = NO;
                }
            } userId:as.user.idStr workId:self.work.id];
            NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@(self.work.id), @"作品id", nil];
            [MobClick event:log_event_name_add_fav_work attributes:dict];
        }
    }

    -(void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
        [self driveScrollView:scrollView lastOffsetY:lastOffsetY scrollViewHeight:scrollViewHeight topView:self.header];
        lastOffsetY = scrollView.contentOffset.y;
    }

    -(void)driveScrollView:(UIScrollView *)scrollView lastOffsetY:(float)_lastOffsetY scrollViewHeight:(float)_scrollViewHeight topView:(UIView *)view{
        if (scrollView.contentOffset.y > 0 && scrollView.contentOffset.y < (scrollView.contentSize.height - scrollView.frame.size.height) && scrollView.contentSize.height > (view.frame.size.height + _scrollViewHeight + general_margin)) {
            if (_lastOffsetY - scrollView.contentOffset.y > 0  && _lastOffsetY < (scrollView.contentSize.height - scrollView.frame.size.height)) {//下拉
                if (view.frame.origin.y != 0) {
                    [UIView animateWithDuration:0.5 animations:^{
                        view.frame = CGRectMake(0, 0, screen_width, view.frame.size.height);
                        scrollView.frame = CGRectMake(0, view.frame.size.height, screen_width,_scrollViewHeight);
                    }];
                }
            }else if (_lastOffsetY - scrollView.contentOffset.y < 0){//上推
                if (view.frame.origin.y != -view.frame.size.height) {
                    [UIView animateWithDuration:0.5 animations:^{
                        view.frame = CGRectMake(0, -view.frame.size.height - splite_line_height, screen_width, view.frame.size.height);
                        scrollView.frame = CGRectMake(0, 0, screen_width, _scrollViewHeight+view.frame.size.height);
                    }];
                }
            }
        }
    }
  • 相关阅读:
    分段路由的复兴
    动态维护FDB表项实现VXLAN通信
    neutron dhcp 高可用
    wpf
    从0到1设计一台8bit计算机
    哇塞的Docker——vscode远程连接Docker容器进行项目开发(三)
    中通消息平台 Kafka 顺序消费线程模型的实践与优化
    飞机大战 python小项目
    看透确定性,抛弃确定性
    如何根据普通ip地址获取当前地理位置
  • 原文地址:https://www.cnblogs.com/xubojoy/p/3885946.html
Copyright © 2011-2022 走看看