首页 > 其他 > 详细

有关通知的简单使用

时间:2014-08-02 01:33:42      阅读:395      评论:0      收藏:0      [点我收藏+]
   //发送通知
    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);
                }];
            }
        }
    }
}

有关通知的简单使用,布布扣,bubuko.com

有关通知的简单使用

原文:http://www.cnblogs.com/xubojoy/p/3885946.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!