Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the right folder function #2

Open
KimSamHyun opened this issue Dec 25, 2016 · 1 comment
Open

Implement the right folder function #2

KimSamHyun opened this issue Dec 25, 2016 · 1 comment

Comments

@KimSamHyun
Copy link

KimSamHyun commented Dec 25, 2016

Using the BEFoldMenuViewController library

I want to put the folder function on the right side but it is not implemented properly.

Have you ever implemented it?

Draggin ok
rightMenuAction function not ok

Implementation Source
//
// BEFoldMenuViewController.m
// vozForums
//
// Created by Vũ Trường Giang on 7/21/16.
// Copyright © 2016 Vũ Trường Giang. All rights reserved.
//

#import "BEFoldMenuViewController.h"
#import "UIView+Frame.h"

...

-(void)initCaptureLayer{
UIImage * viewImage = nil;
UIImage *leftImage = nil;
UIImage *rightImage = nil;

@autoreleasepool {
    UIGraphicsBeginImageContextWithOptions(_rightViewController.view.bounds.size, NO, [UIScreen mainScreen].scale);
    [_rightViewController.view drawViewHierarchyInRect:CGRectMake(0, 0, _rightViewController.view.bounds.size.width, _rightViewController.view.bounds.size.height) afterScreenUpdates:NO];
    viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    CGSize halfsize = CGSizeMake(viewImage.size.width / 2, viewImage.size.height);
    CGSize fullsize = CGSizeMake(viewImage.size.width, viewImage.size.height);
    
    // The left half of the image >> full image
    UIGraphicsBeginImageContextWithOptions(fullsize, YES, [UIScreen mainScreen].scale);
    [viewImage drawAtPoint:CGPointMake(0, 0) blendMode:kCGBlendModeNormal alpha:1.0];
    leftImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    
    UIGraphicsBeginImageContextWithOptions(halfsize, YES, [UIScreen mainScreen].scale);
    [viewImage drawAtPoint:CGPointMake(0, 0) blendMode:kCGBlendModeNormal alpha:1.0];
    rightImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
}

if (!_overlayPerspectiveView) {
    
    CGFloat width = _rightMenuWidth;
    CGFloat height = SCREEN_HEIGHT;
    _overlayPerspectiveView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
    _overlayPerspectiveView.backgroundColor = [UIColor blackColor];
    _overlayPerspectiveView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
    
    _perspectiveLayer = [CALayer layer];
    _perspectiveLayer.frame = CGRectMake(0, 0, width/2, height);
    _perspectiveLayer.anchorPoint = CGPointMake(1, 0.5);
    _perspectiveLayer.position = CGPointMake(width/2, height/2);
    [_overlayPerspectiveView.layer addSublayer:_perspectiveLayer];
    
    _firstJointLayer = [CATransformLayer layer];
    _firstJointLayer.frame = _overlayPerspectiveView.bounds;
    _firstJointLayer.anchorPoint = CGPointMake(1, 0.5);
    _firstJointLayer.position = CGPointMake(width, height/2);
    [_perspectiveLayer addSublayer:_firstJointLayer];
    
    _topSleeve = [CALayer layer];
    _topSleeve.frame = CGRectMake(0, 0, width, height);
    _topSleeve.anchorPoint = CGPointMake(0, 0.5);
    _topSleeve.position = CGPointMake(0, height/2);
    _topSleeve.contents = (__bridge id)[leftImage CGImage];
    _topSleeve.masksToBounds = NO;
    [_firstJointLayer addSublayer:_topSleeve];
    
    _secondJointLayer = [CATransformLayer layer];
    _secondJointLayer.frame = CGRectMake(0, 0, width, height);
    _secondJointLayer.anchorPoint = CGPointMake(1, 0.5);
    _secondJointLayer.position = CGPointMake(width/2, height/2);
    [_firstJointLayer addSublayer:_secondJointLayer];
    
    _middleSleeve = [CALayer layer];
    _middleSleeve.frame = CGRectMake(0, 0, width/2, height);
    _middleSleeve.anchorPoint = CGPointMake(0, 0.5);
    _middleSleeve.position = CGPointMake(width/2, height/2);
    _middleSleeve.contents = (__bridge id)[rightImage CGImage];
    _middleSleeve.masksToBounds = YES;
    [_secondJointLayer addSublayer:_middleSleeve];
    
    _middleShadow = [CALayer layer];
    [_middleSleeve addSublayer:_middleShadow];
    _middleShadow.frame = _middleSleeve.bounds;
    _middleShadow.backgroundColor = [UIColor blackColor].CGColor;
    _middleShadow.opacity = 0.0;
    
    _transform3DEffect = CATransform3DIdentity;
    _transform3DEffect.m34 = 1.0/(-2000.0);
    _perspectiveLayer.sublayerTransform = _transform3DEffect;
    
    [_rightViewController.view addSubview:_overlayPerspectiveView];
    
}else{
    [CATransaction begin];
    [CATransaction setDisableActions:YES];
    
    _topSleeve.contents = (id)leftImage.CGImage;
    _middleSleeve.contents = (id)rightImage.CGImage;
    
    [_rightViewController.view addSubview:_overlayPerspectiveView];
    [CATransaction commit];
}
[_rightViewController.view bringSubviewToFront:_overlayPerspectiveView];

}

...

#pragma mark - Private method
-(void)foldViewWithSpace:(CGFloat) space{
CGFloat theSpace = space > 0 ? space : -space;

CGFloat ratio = theSpace/_rightViewController.view.width;
//Cạnh kề
CGFloat adjacentEdge = theSpace/2;

//Cạnh huyền
CGFloat hypotenuseEdge = _rightViewController.view.width/2;

CGFloat angle = acos(adjacentEdge/hypotenuseEdge);


[CATransaction begin];
[CATransaction setDisableActions:YES]; // no animations
if (_foldEffeectEnabled == YES) {
    _firstJointLayer.transform = CATransform3DMakeRotation(-angle, 0.0, 1.0, 0.0);
    
    _secondJointLayer.transform = CATransform3DMakeRotation(2*angle, 0.0, 1.0, 0.0);
    
    _middleShadow.opacity = 0.3*(1-ratio);
}

_mainViewController.view.transform = CGAffineTransformMakeTranslation(space, 0);
[CATransaction commit];

}

-(void)animateWithState:(BSMenuState)menuState duration:(NSTimeInterval) duration
{
__weak BEFoldMenuViewController *weakSelf = self;

__block CGFloat foldAngle = 0.0f;
__block CGFloat foldOpacity = 0.0f;
__block CGFloat translationX = 0.0f;

__block BSMenuState _theMenuState = menuState;

switch (menuState) {
    case BSMenuStateLeftOpen:{
        if (_leftMenuEnabled == YES) {
            foldAngle = 0.0f;
            foldOpacity = 0.0f;
            translationX = _leftMenuWidth;
            break;
        }//else go to next case
    }
    case BSMenuStateRightOpen:{
        
        if (_rightMenuEnabled == YES) {
            foldAngle = 0.0f;
            foldOpacity = 0.0f;
            translationX = -_rightMenuWidth;
            break;
        }// else go to next case
    }
    case BSMenuStateCenterOpen:{
        _theMenuState = BSMenuStateCenterOpen;
        foldAngle = M_PI_2;
        foldOpacity = FOLD_OPACITY_MAXIMUM;
        translationX = 0.0f;
        break;
    }
    default:
        break;
}

if (_leftMenuEnabled == NO && _rightMenuEnabled == NO) {
    _theMenuState = BSMenuStateCenterOpen;
    foldAngle = M_PI_2;
    foldOpacity = FOLD_OPACITY_MAXIMUM;
    translationX = 0.0f;
}

[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
if (_delegate && [_delegate respondsToSelector:@selector(foldMenuControllerWillStartAnimation:duration:)]) {
    [_delegate foldMenuControllerWillStartAnimation:weakSelf duration:duration];
}else{
    NSLog(@"%s Delegate not response to selector",__PRETTY_FUNCTION__);
}
[CATransaction begin];
CABasicAnimation*  animation = nil;

if (_foldEffeectEnabled == YES) {
    animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
    [animation setDuration:duration];
    [animation setAutoreverses:NO];
    [animation setRepeatCount:0];
    animation.fillMode = kCAFillModeForwards;
    animation.removedOnCompletion = NO;
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
    [animation setFromValue:[NSNumber numberWithFloat:_middleShadow.opacity]];
    [animation setToValue:[NSNumber numberWithDouble:foldOpacity]];
    [_middleShadow addAnimation:animation forKey:@"middleShadow.opacity"];
    
    animation = [CABasicAnimation animationWithKeyPath:@"transform"];
    [animation setDuration:duration];
    [animation setAutoreverses:NO];
    [animation setRepeatCount:0];
    animation.fillMode = kCAFillModeForwards;
    animation.removedOnCompletion = NO;
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
    [animation setFromValue:[NSValue valueWithCATransform3D:_firstJointLayer.transform]];
    [animation setToValue:[NSValue valueWithCATransform3D:CATransform3DMakeRotation(-foldAngle, 0.0, 1.0, 0.0)]];
    [_firstJointLayer addAnimation:animation forKey:@"firstJointLayer.transform"];
    
    animation = [CABasicAnimation animationWithKeyPath:@"transform"];
    [animation setDuration:duration];
    [animation setAutoreverses:NO];
    [animation setRepeatCount:0];
    animation.fillMode = kCAFillModeForwards;
    animation.removedOnCompletion = NO;
    animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
    [animation setFromValue:[NSValue valueWithCATransform3D:_secondJointLayer.transform]];
    [animation setToValue:[NSValue valueWithCATransform3D:CATransform3DMakeRotation(2*foldAngle, 0.0, 1.0, 0.0)]];
    [_secondJointLayer addAnimation:animation forKey:@"secondJointLayer.transform"];
}

animation = [CABasicAnimation animationWithKeyPath:@"transform"];
[animation setDuration:duration];
[animation setAutoreverses:NO];
[animation setRepeatCount:0];
animation.fillMode = kCAFillModeForwards;
animation.removedOnCompletion = NO;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
[animation setFromValue:[NSValue valueWithCATransform3D:_mainViewController.view.layer.transform]];
[animation setToValue:[NSValue valueWithCATransform3D:CATransform3DMakeTranslation(translationX, 0, 0)]];

...
}

@werfe
Copy link
Owner

werfe commented Jan 9, 2017

Oh, sorry, I haven't implemented it. I wish i could, but I do not have time now, really sorry. You can read my code, and do what you want in similar way. Sorry for can not help you right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants