美文网首页
下拉菜单简易例子

下拉菜单简易例子

作者: CaptainRoy | 来源:发表于2018-11-06 13:44 被阅读0次
    -(UIButton *)menuItem
    {
        if (!_menuItem) {
            _menuItem = [UIButton buttonWithType:UIButtonTypeCustom];
            _menuItem.frame = CGRectMake(0.0f, 20.0f, self.view.frame.size.width, 44.0f);
            [_menuItem setBackgroundColor:[UIColor grayColor]];
            [_menuItem setTitle:@"菜单" forState:UIControlStateNormal];
            [_menuItem setTitle:@"筛选" forState:UIControlStateSelected];
            [_menuItem setImage:[UIImage imageNamed:@"icon_zhankai_orange"] forState:UIControlStateNormal];
            [_menuItem addTarget:self action:@selector(dropClick:) forControlEvents:UIControlEventTouchUpInside];
            [self.view addSubview:_menuItem];
        }
        return _menuItem;
    }
    
    -(UIView *)menuView
    {
        if (!_menuView) {
            _menuView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 64.0f, self.view.frame.size.width, 0.0f )];
            _menuView.backgroundColor = [UIColor greenColor];
            [self.view addSubview:_menuView];
        }
        return _menuView;
    }
    
    #pragma mark - dropClick
    -(void)dropClick:(UIButton *)button
    {
        button.selected = !button.selected;
        button.selected ? [self show] : [self hide];
    }
    
    -(void)show
    {
        __weak typeof(self) weakSelf = self;
        [UIView animateWithDuration:0.5f animations:^{
            weakSelf.menuView.frame = CGRectMake(0.0f, 64.0f, self.view.frame.size.width, self.view.frame.size.height - 64.0f);
            [[UIApplication sharedApplication].keyWindow addSubview:weakSelf.menuView];
        } completion:NULL];
    }
    
    -(void)hide
    {
        __weak typeof(self) weakSelf = self;
        [UIView animateWithDuration:0.5f animations:^{
            weakSelf.menuView.frame = CGRectMake(0.0f, 64.0f, self.view.frame.size.width,0.0f);
        } completion:^(BOOL finished) {
            [weakSelf.menuView removeFromSuperview];
        }];
    }
    
    图片旋转
    [UIView animateWithDuration:self.animationDuration animations:^{
            if (selected) {
                self.imageView.transform = CGAffineTransformMakeRotation(M_PI);
            } else {
                self.imageView.transform = CGAffineTransformMakeRotation(0.0);
            }
        } completion:^(BOOL finished) {
         
        }];
    

    相关文章

      网友评论

          本文标题:下拉菜单简易例子

          本文链接:https://www.haomeiwen.com/subject/fkcuxqtx.html