有关通知的简单使用

   //发送通知
    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);
                }];
            }
        }
    }
}
posted @ 2014-08-01 22:37  xubojoy  阅读(214)  评论(0编辑  收藏  举报