中间省略了配置导航栏的内容。
这个方法中又一个[_mainContentView.subviews firstObject]方法,这个方法是IOS7才有的,按以前习惯写[0]也好。
实现视图移动动画主要是通过仿射变换来实现的,也有的例子通过操作frame,看习惯了。
一个根据方向返回仿射变换值的私有方法
- (CGAffineTransform)transformWithDirection:(RMoveDirection)direction
{
CGFloat translateX = 0;
switch (direction) {
case RMoveDirectionLeft:
translateX = -RContentOffset;
break;
case RMoveDirectionRight:
translateX = RContentOffset;
break;
default:
break;
}
MyLog(@"%.2f",translateX);
CGAffineTransform transT = CGAffineTransformMakeTranslation(translateX, 0);
CGAffineTransform scaleT = CGAffineTransformMakeScale(1.0, RContentScale);
CGAffineTransform conT = CGAffineTransformConcat(transT, scaleT);
return conT;
}
一个根据方向配置页面的阴影效果的私有方法
- (void)configureViewShadowWithDirection:(RMoveDirection)direction
{
CGFloat shadowW;
switch (direction)
{
case RMoveDirectionLeft:
shadowW = 2.0f;
break;
case RMoveDirectionRight:
shadowW = -2.0f;
break;
default:
break;
}
_mainContentView.layer.shadowOffset = CGSizeMake(shadowW, 1.0);
_mainContentView.layer.shadowColor = [UIColor blackColor].CGColor;
_mainContentView.layer.shadowOpacity = 0.8f;
}
点击导航栏左侧按钮的展开侧栏方法(右侧类似)
- (void)leftItemClick
{
CGAffineTransform conT = [self transformWithDirection:RMoveDirectionRight];
[self.view sendSubviewToBack:_rightSideView];
[self configureViewShadowWithDirection:RMoveDirectionRight];
[UIView animateWithDuration:ROpenDuration
animations:^{
_mainContentView.transform = conT;
}
completion:^(BOOL finished) {
_tapGestureRec.enabled = YES;
}];
}
关闭侧栏返回主页面的方法
- (void)closeSideBar
{
CGAffineTransform oriT = CGAffineTransformIdentity;
[UIView animateWithDuration:RCloseDuration
animations:^{
_mainContentView.transform = oriT;
}
completion:^(BOOL finished) {
_tapGestureRec.enabled = NO;
}];
}