• 有关通知的简单使用


       //发送通知
        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);
                    }];
                }
            }
        }
    }
  • 相关阅读:
    常见的7种排序算法
    ZooKeeper
    线上问题排查(2)——JDK内置工具
    Java并发编程:深入剖析ThreadLocal
    没有main的hello world 程序——Java 分类: java 2015-06-24 16:20 11人阅读 评论(0) 收藏
    Django笔记 —— 模型
    Django笔记 —— MySQL安装
    USACO Section2.3 Controlling Companies 解题报告 【icedream61】
    USACO Section2.3 Money Systems 解题报告 【icedream61】
    USACO Section2.3 Zero Sum 解题报告 【icedream61】
  • 原文地址:https://www.cnblogs.com/xubojoy/p/3885946.html
Copyright © 2020-2023  润新知