一天一工程总结

一天一工程总结
2015
7.1

一天一工程总结系列
对各类优秀工程的剖析和拙见。有些胡言乱语还请作者谅解。

结构较乱,焦点跳跃性较高。目前仅供个人总结用,不适者可选择不观看^^

TStyleMenuView
cocoachina上推荐的仿美团向下展开列表。
横向的itembar 由LSSelectMenuView实现,该类继承自UIView,同时实现了两个代理LSSelectMenuViewDataSource<NSObject>和LSSelectMenuViewDelegate<NSObject>.
通过
[UIView animateWithDuration:DurationTime animations:^{
        sender.markImgView.transform = CGAffineTransformRotate(sender.markImgView.transform, -M_PI);
    } completion:^(BOOL ok){
        if (ok) {

            self.userInteractionEnabled = YES;
        }
    }];
来实现按钮和下拉列表的伸缩动画
工程用一个showview做下拉窗口的背景view,在showview上面做addsubview和removeFromSuperview的操作。且在showview上加一个手势,实现点起收起的操作。
responsechain,收到tap事件的时候,首先在最上层检查是否响应该事件,否则,则向下传递。所以,即使在showview上addsubview,在subview上的点击也能够传递到showview。

showview的大小是满屏,始终覆盖的。只是背景由动画完成,是一种由浅变深的动画。没有上下伸缩的那么突兀。

在items之间不停切换的时候,showview并不改变状态,仍然是半透明颜色,占满屏。
点击某一个item打开和收缩的时候,会有颜色渐变的动画。所以,跟showview配对的还有一个accessibilityIdentifier标示showview的颜色状态。代码中showview有一个高度的变化。对,如果不做高度的变化,关闭之后,点击不了背后的view。

下拉视图的关闭
[UIView animateWithDuration:DurationTime animations:^{
        //
        vv.frame = CGRectMake(0, 0, vv.frame.size.width, 0);
    }completion:^(BOOL finished) {
        //
        [vv removeFromSuperview];
    }];
关闭背景
        [UIView animateWithDuration:DurationTime animations:^{
            //
            _showView.backgroundColor = [UIColor colorWithRed:0.145 green:0.145 blue:0.145 alpha:0];
            
        }completion:^(BOOL finished) {
            //
            _showView.frame = minShowRect;
            _showView.accessibilityIdentifier = @"NO";
        }];

accessibilityIdentifier
UIAccessibilityIdentification
The UIAccessibilityIdentification protocol is used to associate a unique identifier with elements in your user interface.
UIAccessbilityElement *elelment = [[UIApplication sharedApplication] accessbilityElementWithLabel:label];
UIView *view = (UIView*)[UIAccessibilityElement viewContainingAccessbilityElement:element];
类似tag的作用。快速寻找一个view。

该类的缺点是
1.下拉页面不独立,合并在LSSelectMenuView中
2.按钮的点击在处理点击事件的一开始就禁掉了,到动画完成才打开。可能是为了规避动画冲突,但是作为主要的action焦点,点击无效果对用户体验的影响很大。

原文地址:https://www.cnblogs.com/so-magic/p/4616472.html