// ViewController.m
// 抽屉效果
// 备注:代码封装,直接用
// Created by RHP
// Copyright (c) RHP. All rights reserved.
#import "ViewController.h"
@interface ViewController ()
@property ( nonatomic , weak ) UIView *leftV;
@property ( nonatomic , weak ) UIView *rightV;
@property ( nonatomic , weak ) UIView *mainV;
// 判断当前是否在拖拽
@property ( nonatomic , assign ) BOOL isDraging;
@end
@implementation ViewController
- ( void )viewDidLoad {
[ super viewDidLoad ];
//1. 添加子控件
[ self addAllChildView ];
//2. 添加观察者 (KVO), 时刻监听 frame 的移动
[ _mainV addObserver : self forKeyPath : @"frame" options : NSKeyValueObservingOptionNew context : nil ];
}
-( void )observeValueForKeyPath:( NSString *)keyPath ofObject:( id )object change:( NSDictionary *)change context:( void *)context
{
// 向右边拖 , 显示左边 , 隐藏右边
if ( _mainV . frame . origin . x ]]> 0 ) {
_leftV . hidden = NO ;
_rightV . hidden =
// 抽屉效果
// 备注:代码封装,直接用
// Created by RHP
// Copyright (c) RHP. All rights reserved.
#import "ViewController.h"
@interface ViewController ()
@property ( nonatomic , weak ) UIView *leftV;
@property ( nonatomic , weak ) UIView *rightV;
@property ( nonatomic , weak ) UIView *mainV;
// 判断当前是否在拖拽
@property ( nonatomic , assign ) BOOL isDraging;
@end
@implementation ViewController
- ( void )viewDidLoad {
[ super viewDidLoad ];
//1. 添加子控件
[ self addAllChildView ];
//2. 添加观察者 (KVO), 时刻监听 frame 的移动
[ _mainV addObserver : self forKeyPath : @"frame" options : NSKeyValueObservingOptionNew context : nil ];
}
-( void )observeValueForKeyPath:( NSString *)keyPath ofObject:( id )object change:( NSDictionary *)change context:( void *)context
{
// 向右边拖 , 显示左边 , 隐藏右边
if ( _mainV . frame . origin . x ]]> 0 ) {
_leftV . hidden = NO ;
_rightV . hidden =