下拉菜单简易例子

-(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) {
     
    }];

你可能感兴趣的:(下拉菜单简易例子)