你好,游客 登录 注册 搜索
背景:
阅读新闻

iOS仿网易新闻客户端左右侧栏

[日期:2013-10-15] 来源:Linux社区  作者:RannieR [字体:大 中 小]

中间省略了配置导航栏的内容。

这个方法中又一个[_mainContentView.subviews firstObject]方法,这个方法是IOS7才有的,按以前习惯写[0]也好。

实现视图移动动画主要是通过仿射变换来实现的,也有的例子通过操作frame,看习惯了。

一个根据方向返回仿射变换值的私有方法

- (CGAffineTransform)transformWithDirection:(RMoveDirection)direction
{
    CGFloat translateX = 0;
    switch (direction) {
        case RMoveDirectionLeft:
            translateX = -RContentOffset;
            break;
        case RMoveDirectionRight:
            translateX = RContentOffset;
            break;
        default:
            break;
    }
   
    MyLog(@"%.2f",translateX);
    CGAffineTransform transT = CGAffineTransformMakeTranslation(translateX, 0);
    CGAffineTransform scaleT = CGAffineTransformMakeScale(1.0, RContentScale);
    CGAffineTransform conT = CGAffineTransformConcat(transT, scaleT);
   
    return conT;
}

一个根据方向配置页面的阴影效果的私有方法

- (void)configureViewShadowWithDirection:(RMoveDirection)direction
{
    CGFloat shadowW;
    switch (direction)
    {
        case RMoveDirectionLeft:
            shadowW = 2.0f;
            break;
        case RMoveDirectionRight:
            shadowW = -2.0f;
            break;
        default:
            break;
    }
   
    _mainContentView.layer.shadowOffset = CGSizeMake(shadowW, 1.0);
    _mainContentView.layer.shadowColor = [UIColor blackColor].CGColor;
    _mainContentView.layer.shadowOpacity = 0.8f;
}

点击导航栏左侧按钮的展开侧栏方法(右侧类似)

- (void)leftItemClick
{
    CGAffineTransform conT = [self transformWithDirection:RMoveDirectionRight];
   
    [self.view sendSubviewToBack:_rightSideView];
    [self configureViewShadowWithDirection:RMoveDirectionRight];
   
    [UIView animateWithDuration:ROpenDuration
                    animations:^{
                        _mainContentView.transform = conT;
                    }
                    completion:^(BOOL finished) {
                        _tapGestureRec.enabled = YES;
                    }];
}

关闭侧栏返回主页面的方法

- (void)closeSideBar
{
    CGAffineTransform oriT = CGAffineTransformIdentity;
    [UIView animateWithDuration:RCloseDuration
                    animations:^{
                        _mainContentView.transform = oriT;
                    }
                    completion:^(BOOL finished) {
                        _tapGestureRec.enabled = NO;
                    }];
}

linux
相关资讯       iOS编程  iOS仿网易新闻客户端 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款