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

Added support for 3D transformations #172

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
3076CE0E1809B5C500527E6C /* RESideMenu.m in Sources */ = {isa = PBXBuildFile; fileRef = 3076CE0A1809B5C500527E6C /* RESideMenu.m */; };
3076CE0F1809B5C500527E6C /* UIViewController+RESideMenu.m in Sources */ = {isa = PBXBuildFile; fileRef = 3076CE0C1809B5C500527E6C /* UIViewController+RESideMenu.m */; };
30DF13B218DE1B0C0018463C /* DEMORightMenuViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 30DF13B118DE1B0C0018463C /* DEMORightMenuViewController.m */; };
F8C68E8219D2A60300AB185E /* MCBTransform3DHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = F8C68E8119D2A60300AB185E /* MCBTransform3DHandler.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -69,6 +70,8 @@
3076CE0C1809B5C500527E6C /* UIViewController+RESideMenu.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIViewController+RESideMenu.m"; sourceTree = "<group>"; };
30DF13B018DE1B0C0018463C /* DEMORightMenuViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DEMORightMenuViewController.h; sourceTree = "<group>"; };
30DF13B118DE1B0C0018463C /* DEMORightMenuViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DEMORightMenuViewController.m; sourceTree = "<group>"; };
F8C68E8019D2A60300AB185E /* MCBTransform3DHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCBTransform3DHandler.h; sourceTree = "<group>"; };
F8C68E8119D2A60300AB185E /* MCBTransform3DHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MCBTransform3DHandler.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -171,6 +174,8 @@
children = (
3076CE071809B5C400527E6C /* RECommonFunctions.h */,
3076CE081809B5C400527E6C /* RECommonFunctions.m */,
F8C68E8019D2A60300AB185E /* MCBTransform3DHandler.h */,
F8C68E8119D2A60300AB185E /* MCBTransform3DHandler.m */,
3076CE091809B5C400527E6C /* RESideMenu.h */,
3076CE0A1809B5C500527E6C /* RESideMenu.m */,
3076CE0B1809B5C500527E6C /* UIViewController+RESideMenu.h */,
Expand Down Expand Up @@ -228,6 +233,9 @@
LastUpgradeCheck = 0510;
ORGANIZATIONNAME = "Roman Efimov";
TargetAttributes = {
3076CDBD1809B47200527E6C = {
DevelopmentTeam = 8DEWPT2VGB;
};
3076CDDE1809B47200527E6C = {
TestTargetID = 3076CDBD1809B47200527E6C;
};
Expand Down Expand Up @@ -277,6 +285,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
F8C68E8219D2A60300AB185E /* MCBTransform3DHandler.m in Sources */,
3076CE021809B59E00527E6C /* DEMOLeftMenuViewController.m in Sources */,
3076CE011809B59E00527E6C /* DEMOFirstViewController.m in Sources */,
3076CDCE1809B47200527E6C /* main.m in Sources */,
Expand Down Expand Up @@ -402,11 +411,14 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "RESideMenuStoryboardsExample/RESideMenuStoryboardsExample-Prefix.pch";
INFOPLIST_FILE = "RESideMenuStoryboardsExample/RESideMenuStoryboardsExample-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
TARGETED_DEVICE_FAMILY = "1,2";
WRAPPER_EXTENSION = app;
};
Expand All @@ -417,11 +429,14 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "RESideMenuStoryboardsExample/RESideMenuStoryboardsExample-Prefix.pch";
INFOPLIST_FILE = "RESideMenuStoryboardsExample/RESideMenuStoryboardsExample-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
TARGETED_DEVICE_FAMILY = "1,2";
WRAPPER_EXTENSION = app;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,34 @@
<key>IDESourceControlProjectFavoriteDictionaryKey</key>
<false/>
<key>IDESourceControlProjectIdentifier</key>
<string>3879733F-3A95-4277-B781-69031D14BC32</string>
<string>89C8A5DD-AD46-44A9-A9D9-45125238F62B</string>
<key>IDESourceControlProjectName</key>
<string>RESideMenuStoryboardsExample</string>
<key>IDESourceControlProjectOriginsDictionary</key>
<dict>
<key>D8E9CD00-2368-4ABD-BD15-AB69D787B293</key>
<string>ssh://github.com/romaonthego/RESideMenu.git</string>
<key>4D9AE519C7D7E765CA7498EFD8B3BB24ACB11215</key>
<string>https://github.com/r00li/RESideMenu.git</string>
</dict>
<key>IDESourceControlProjectPath</key>
<string>Examples/Storyboards/RESideMenuStoryboardsExample.xcodeproj/project.xcworkspace</string>
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
<dict>
<key>D8E9CD00-2368-4ABD-BD15-AB69D787B293</key>
<key>4D9AE519C7D7E765CA7498EFD8B3BB24ACB11215</key>
<string>../../../..</string>
</dict>
<key>IDESourceControlProjectURL</key>
<string>ssh://github.com/romaonthego/RESideMenu.git</string>
<string>https://github.com/r00li/RESideMenu.git</string>
<key>IDESourceControlProjectVersion</key>
<integer>110</integer>
<integer>111</integer>
<key>IDESourceControlProjectWCCIdentifier</key>
<string>D8E9CD00-2368-4ABD-BD15-AB69D787B293</string>
<string>4D9AE519C7D7E765CA7498EFD8B3BB24ACB11215</string>
<key>IDESourceControlProjectWCConfigurations</key>
<array>
<dict>
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
<string>public.vcs.git</string>
<key>IDESourceControlWCCIdentifierKey</key>
<string>D8E9CD00-2368-4ABD-BD15-AB69D787B293</string>
<string>4D9AE519C7D7E765CA7498EFD8B3BB24ACB11215</string>
<key>IDESourceControlWCCName</key>
<string>RESideMenu</string>
</dict>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright (c) 2013 Roman Efimov. All rights reserved.
//

#import "MCBTransform3DHandler.h"
#import "DEMORootViewController.h"
#import "DEMOLeftMenuViewController.h"

Expand All @@ -24,6 +25,41 @@ - (void)awakeFromNib
self.contentViewShadowRadius = 12;
self.contentViewShadowEnabled = YES;

self.contentViewScaleValue = 0.6;
self.contentViewInPortraitOffsetCenterX = -220;

//Enable 3D transformations
self.use3DTransform = YES;


//
// 3D transformation
// right menu
//
CATransform3D rotationAndPerspectiveTransformRight = CATransform3DIdentity;
rotationAndPerspectiveTransformRight.m34 = 1.0 / -500;
rotationAndPerspectiveTransformRight = CATransform3DRotate(rotationAndPerspectiveTransformRight, 25 * M_PI / 180.0f, 0.0f, 1.0f, 0.0f);
rotationAndPerspectiveTransformRight = CATransform3DTranslate(rotationAndPerspectiveTransformRight, -200, 0, 50);
rotationAndPerspectiveTransformRight = CATransform3DScale(rotationAndPerspectiveTransformRight, self.contentViewScaleValue, self.contentViewScaleValue, 1);
self.rightMenu3DTransform = rotationAndPerspectiveTransformRight;


//
// 3D transformation
// left menu
//
/*
CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
rotationAndPerspectiveTransform.m34 = 1.0 / -500;
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, -25 * M_PI / 180.0f, 0.0f, 1.0f, 0.0f);
rotationAndPerspectiveTransform = CATransform3DTranslate(rotationAndPerspectiveTransform, 170, 0, 0);
rotationAndPerspectiveTransform = CATransform3DScale(rotationAndPerspectiveTransform, self.contentViewScaleValue, self.contentViewScaleValue, 1);
self.leftMenu3DTransform = rotationAndPerspectiveTransform;
*/

MCBTransform3DPerspectiveRotation *transformHandler = [[MCBTransform3DPerspectiveRotation alloc] init];
self.leftMenu3DTransform = [transformHandler interpolatedTransformWithScale:1.0f];

self.contentViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"contentViewController"];
self.leftMenuViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"leftMenuViewController"];
self.rightMenuViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"rightMenuViewController"];
Expand Down
20 changes: 20 additions & 0 deletions RESideMenu/MCBTransform3DHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// MCBTransform3DHandler.h
// Minicabster
//
// Created by Matic Oblak on 9/23/14.
// Copyright (c) 2014 D·Labs. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface MCBTransform3DHandler : NSObject
- (CATransform3D)interpolatedTransformWithScale:(CGFloat)scale;
@end

@interface MCBTransform3DPerspectiveRotation : MCBTransform3DHandler
@property (nonatomic) CGFloat perspectiveStrength; // default -500
@property (nonatomic) CGFloat rotationY; // default -M_PI/6
@property (nonatomic) CGFloat translationX; // default 170
@property (nonatomic) CGFloat scaleXY; // default 0.62f
@end
111 changes: 111 additions & 0 deletions RESideMenu/MCBTransform3DHandler.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
//
// MCBTransform3DHandler.m
// Minicabster
//
// Created by Matic Oblak on 9/23/14.
// Copyright (c) 2014 D·Labs. All rights reserved.
//

#import "MCBTransform3DHandler.h"

@implementation MCBTransform3DHandler

+ (CATransform3D)interpolateMatrices:(CATransform3D)source to:(CATransform3D)target scale:(CGFloat)scale
{
CATransform3D result;

result.m11 = [self interpolateLinear:source.m11 to:target.m11 scale:scale];
result.m12 = [self interpolateLinear:source.m12 to:target.m12 scale:scale];
result.m13 = [self interpolateLinear:source.m13 to:target.m13 scale:scale];
result.m14 = [self interpolateLinear:source.m14 to:target.m14 scale:scale];

result.m21 = [self interpolateLinear:source.m21 to:target.m21 scale:scale];
result.m22 = [self interpolateLinear:source.m22 to:target.m22 scale:scale];
result.m23 = [self interpolateLinear:source.m23 to:target.m23 scale:scale];
result.m24 = [self interpolateLinear:source.m24 to:target.m24 scale:scale];

result.m31 = [self interpolateLinear:source.m31 to:target.m31 scale:scale];
result.m32 = [self interpolateLinear:source.m32 to:target.m32 scale:scale];
result.m33 = [self interpolateLinear:source.m33 to:target.m33 scale:scale];
result.m34 = [self interpolateLinear:source.m34 to:target.m34 scale:scale];

result.m41 = [self interpolateLinear:source.m41 to:target.m41 scale:scale];
result.m42 = [self interpolateLinear:source.m42 to:target.m42 scale:scale];
result.m43 = [self interpolateLinear:source.m43 to:target.m43 scale:scale];
result.m44 = [self interpolateLinear:source.m44 to:target.m44 scale:scale];

return result;
}

- (CATransform3D)interpolatedTransformWithScale:(CGFloat)scale
{
return CATransform3DIdentity;
}

+ (CGFloat)interpolateLinear:(CGFloat)a to:(CGFloat)b scale:(CGFloat)scale
{
return a + (b-a)*scale;
}


@end

@implementation MCBTransform3DPerspectiveRotation

- (instancetype)init
{
if((self = [super init]))
{
// set defaults
self.perspectiveStrength = -500.0f;
self.rotationY = (CGFloat)(-M_PI_2/3.0);
self.translationX = 170.0f;
self.scaleXY = .62f;
}
return self;
}

- (CATransform3D)interpolatedTransformWithScale:(CGFloat)scale
{
CGFloat interpolatedPerspective = self.perspectiveStrength;
CGFloat interpolatedRotationY = [self interpolate:.0f to:self.rotationY scale:1.0f];
CGFloat interpolatedTranslation = [self interpolate:.0f to:self.translationX scale:1.0f];
CGFloat interpolatedScaleXY = [self interpolate:1.0f to:self.scaleXY scale:1.0f];

//NSLog(@"Scale: %g, irotation: %g", scale, interpolatedRotationY);

CATransform3D interpolatedTransformation = CATransform3DIdentity;
interpolatedTransformation.m34 = 1.0f / interpolatedPerspective;
interpolatedTransformation = CATransform3DRotate(interpolatedTransformation, interpolatedRotationY, 0.0f, 1.0f, 0.0f);
interpolatedTransformation = CATransform3DTranslate(interpolatedTransformation, interpolatedTranslation, 0, 0);
interpolatedTransformation = CATransform3DScale(interpolatedTransformation, interpolatedScaleXY, interpolatedScaleXY, 1);

return [MCBTransform3DPerspectiveRotation interpolateMatrices:CATransform3DIdentity to:interpolatedTransformation scale:scale];
}


//- (CATransform3D)interpolatedTransformWithScale:(CGFloat)scale
//{
// CGFloat interpolatedPerspective = self.perspectiveStrength;
// CGFloat interpolatedRotationY = [self interpolate:.0f to:self.rotationY scale:scale];
// CGFloat interpolatedTranslation = [self interpolate:.0f to:self.translationX scale:scale];
// CGFloat interpolatedScaleXY = [self interpolate:1.0f to:self.scaleXY scale:scale];
//
// NSLog(@"Scale: %g, irotation: %g", scale, interpolatedRotationY);
//
// CATransform3D interpolatedTransformation = CATransform3DIdentity;
// interpolatedTransformation.m34 = 1.0f / interpolatedPerspective;
// interpolatedTransformation = CATransform3DRotate(interpolatedTransformation, interpolatedRotationY, 0.0f, 1.0f, 0.0f);
// interpolatedTransformation = CATransform3DTranslate(interpolatedTransformation, interpolatedTranslation, 0, 0);
// interpolatedTransformation = CATransform3DScale(interpolatedTransformation, interpolatedScaleXY, interpolatedScaleXY, 1);
//
// return interpolatedTransformation;
//}

- (CGFloat)interpolate:(CGFloat)a to:(CGFloat)b scale:(CGFloat)scale
{
return a + (b-a)*scale;
}


@end
8 changes: 8 additions & 0 deletions RESideMenu/RESideMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@
@property (assign, readwrite, nonatomic) UIStatusBarStyle menuPreferredStatusBarStyle;
@property (assign, readwrite, nonatomic) BOOL menuPrefersStatusBarHidden;

//
// 3D transformations
//
@property (assign, readwrite, nonatomic) BOOL use3DTransform;
@property (assign, readwrite, nonatomic) CATransform3D leftMenu3DTransform;
@property (assign, readwrite, nonatomic) CATransform3D rightMenu3DTransform;


- (id)initWithContentViewController:(UIViewController *)contentViewController
leftMenuViewController:(UIViewController *)leftMenuViewController
rightMenuViewController:(UIViewController *)rightMenuViewController;
Expand Down
Loading