抽屉效果功能实现
一、.h文件
@interface
HMDrawViewController :
UIViewController
@property ( nonatomic , weak , readonly ) UIView *mainView;
@property ( nonatomic , weak , readonly ) UIView *leftView;
@property ( nonatomic , weak , readonly ) UIView *rightView;
@end
@property ( nonatomic , weak , readonly ) UIView *mainView;
@property ( nonatomic , weak , readonly ) UIView *leftView;
@property ( nonatomic , weak , readonly ) UIView *rightView;
@end
二、.m文件
@interface
HMDrawViewController
()
@property ( nonatomic , assign ) BOOL isDraging;
@end
@implementation HMDrawViewController
- ( void )viewDidLoad
{
// UIViewController
[ super viewDidLoad ];
// Do any additional setup after loading the view.
// 1. 添加子控件
[ self addChildView ];
#warning 第三步 观察 _mainView 的 frame 改变
// 2. 监听
/**
* 给 _mainView 添加一个观察者
*
* KeyPath :监听 frame 这个属性
*
* options :监听新值的改变
*/
[ _mainView addObserver : self forKeyPath : @"frame" options : NSKeyValueObservingOptionNew context : nil ];
}
// 当 _mainView 的 frame 属性改变的时候就会调用
- ( void )observeValueForKeyPath:( NSString *)keyPath ofObject:( id )object change:( NSDictionary *)change context:( void *)context
{
NSLog ( @"%@" , NSStringFromCGRect (