Skip to content

Add independent X/Y scaling for view controllers #1

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

Open
wants to merge 2 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
20 changes: 20 additions & 0 deletions A_ViewContainer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
692ED1FF1B64132D00E29E02 /* A_ViewBaseController.m in Sources */ = {isa = PBXBuildFile; fileRef = 692ED1FE1B64132D00E29E02 /* A_ViewBaseController.m */; };
692ED2031B649F0600E29E02 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 692ED2021B649F0600E29E02 /* ViewController.m */; };
692ED2061B649F5200E29E02 /* DemoLabelViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 692ED2051B649F5200E29E02 /* DemoLabelViewController.m */; };
757572401BD3B0CF00A71B02 /* ViewControllerProgrammatic.m in Sources */ = {isa = PBXBuildFile; fileRef = 7575723F1BD3B0CF00A71B02 /* ViewControllerProgrammatic.m */; settings = {ASSET_TAGS = (); }; };
757572431BD3B20D00A71B02 /* DemoLabelViewControllerShadow.m in Sources */ = {isa = PBXBuildFile; fileRef = 757572421BD3B20D00A71B02 /* DemoLabelViewControllerShadow.m */; settings = {ASSET_TAGS = (); }; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -35,6 +37,10 @@
692ED2021B649F0600E29E02 /* ViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ViewController.m; path = Example/ViewController.m; sourceTree = "<group>"; };
692ED2041B649F5200E29E02 /* DemoLabelViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DemoLabelViewController.h; path = Example/DemoLabelViewController.h; sourceTree = "<group>"; };
692ED2051B649F5200E29E02 /* DemoLabelViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = DemoLabelViewController.m; path = Example/DemoLabelViewController.m; sourceTree = "<group>"; };
7575723E1BD3B0CF00A71B02 /* ViewControllerProgrammatic.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ViewControllerProgrammatic.h; path = Example/ViewControllerProgrammatic.h; sourceTree = "<group>"; };
7575723F1BD3B0CF00A71B02 /* ViewControllerProgrammatic.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ViewControllerProgrammatic.m; path = Example/ViewControllerProgrammatic.m; sourceTree = "<group>"; };
757572411BD3B20D00A71B02 /* DemoLabelViewControllerShadow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DemoLabelViewControllerShadow.h; path = Example/DemoLabelViewControllerShadow.h; sourceTree = "<group>"; };
757572421BD3B20D00A71B02 /* DemoLabelViewControllerShadow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = DemoLabelViewControllerShadow.m; path = Example/DemoLabelViewControllerShadow.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -68,6 +74,7 @@
isa = PBXGroup;
children = (
692ED2001B649EC900E29E02 /* Example */,
757572441BD3B2A500A71B02 /* Example Programmatic */,
692ED1FC1B6412C900E29E02 /* A_ViewContainer */,
692ED1D71B64123C00E29E02 /* AppDelegate.h */,
692ED1D81B64123C00E29E02 /* AppDelegate.m */,
Expand Down Expand Up @@ -110,6 +117,17 @@
name = Example;
sourceTree = "<group>";
};
757572441BD3B2A500A71B02 /* Example Programmatic */ = {
isa = PBXGroup;
children = (
7575723E1BD3B0CF00A71B02 /* ViewControllerProgrammatic.h */,
7575723F1BD3B0CF00A71B02 /* ViewControllerProgrammatic.m */,
757572411BD3B20D00A71B02 /* DemoLabelViewControllerShadow.h */,
757572421BD3B20D00A71B02 /* DemoLabelViewControllerShadow.m */,
);
name = "Example Programmatic";
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -184,7 +202,9 @@
692ED1FF1B64132D00E29E02 /* A_ViewBaseController.m in Sources */,
692ED1FB1B6412C200E29E02 /* A_MultipleViewContainer.m in Sources */,
692ED1D91B64123C00E29E02 /* AppDelegate.m in Sources */,
757572431BD3B20D00A71B02 /* DemoLabelViewControllerShadow.m in Sources */,
692ED2061B649F5200E29E02 /* DemoLabelViewController.m in Sources */,
757572401BD3B0CF00A71B02 /* ViewControllerProgrammatic.m in Sources */,
692ED1D61B64123C00E29E02 /* main.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
8 changes: 5 additions & 3 deletions A_ViewContainer/A_ViewContainer/A_MultipleViewContainer.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ typedef NS_OPTIONS(NSUInteger, A_MultipleViewStyle) {
@interface A_ContainerSetting: NSObject

// Scale the center controller, if set it toz 1.0f means fill cover the view. Default value is .8f
@property (nonatomic) CGFloat scaleOfCurrent;
@property (nonatomic) CGFloat scaleOfCurrentX;
@property (nonatomic) CGFloat scaleOfCurrentY;

// Scale the previous and next controller. Default value is .4f
@property (nonatomic) CGFloat scaleOfEdge;
@property (nonatomic) CGFloat scaleOfEdgeX;
@property (nonatomic) CGFloat scaleOfEdgeY;

// Displacement of side view, lesser value means closer to the center. Default is 1.0f
@property (nonatomic) CGFloat sideDisplacement;
Expand All @@ -33,7 +35,7 @@ typedef NS_OPTIONS(NSUInteger, A_MultipleViewStyle) {

- (BOOL)hasStyle:(A_MultipleViewStyle)style;
- (A_MultipleViewStyle)currentStyle;

- (void)addStyle:(A_MultipleViewStyle)style;
@end


Expand Down
8 changes: 5 additions & 3 deletions A_ViewContainer/A_ViewContainer/A_MultipleViewContainer.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,10 @@ @implementation A_ContainerSetting {

+ (A_ContainerSetting*)A_DeafultSetting{
A_ContainerSetting *setting = [[A_ContainerSetting alloc] init];
setting.scaleOfCurrent = .8f;
setting.scaleOfEdge = .4f;
setting.scaleOfCurrentX = .8f;
setting.scaleOfCurrentY = .8f;
setting.scaleOfEdgeX = .4f;
setting.scaleOfEdgeY = .4f;
setting.sideDisplacement = 1.0f;

return setting;
Expand Down Expand Up @@ -334,7 +336,7 @@ - (void)A_Display {

[self bringSubviewToFront:[_controllerManager getCurrent].view];

[_controllerManager getCurrent].view.layer.transform = CATransform3DMakeScale(_setting.scaleOfCurrent, _setting.scaleOfCurrent, 1);
[_controllerManager getCurrent].view.layer.transform = CATransform3DMakeScale(_setting.scaleOfCurrentX, _setting.scaleOfCurrentY, 1);

[[_controllerManager getCurrent] setInvisible:NO withAnimation:YES];
}
Expand Down
12 changes: 6 additions & 6 deletions A_ViewContainer/A_ViewContainer/A_ViewBaseController.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -73,29 +73,29 @@ - (NSDictionary *)centerToSideAttributes: (A_ContainerSetting *)setting directio
[animationSet setObject:[NSValue valueWithCGPoint:CGPointMake(0.5f + setting.sideDisplacement, self.view.layer.anchorPoint.y)] forKey:@"anchorPoint"];

if ([setting hasStyle:A_MultipleViewStyleRotate]) {
CATransform3D transform = CATransform3DMakeScale(profileEdgeZoomRate(setting.scaleOfEdge), profileEdgeZoomRate(setting.scaleOfEdge), 1);
CATransform3D transform = CATransform3DMakeScale(profileEdgeZoomRate(setting.scaleOfEdgeX), profileEdgeZoomRate(setting.scaleOfEdgeY), 1);
transform = CATransform3DRotate(transform, profileEdgeRotateAngle, 0.0, 1.0, 0);
transform = CATransform3DPerspect(transform, CGPointMake(0, 0), perspectDistance);

[animationSet setObject:[NSValue valueWithCATransform3D:transform] forKey:@"transform"];
// [animationSet setObject:[NSValue valueWithCGPoint:CGPointMake(self.view.layer.position.x - (self.view.layer.bounds.size.width / 2.8), self.view.layer.position.y)] forKey:@"position"];
} else {
[animationSet setObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(setting.scaleOfEdge, setting.scaleOfEdge, 1)] forKey:@"transform"];
[animationSet setObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(setting.scaleOfEdgeX, setting.scaleOfEdgeY, 1)] forKey:@"transform"];
}
}
break;
case A_ControllerDirectionToRight: {
[animationSet setObject:[NSValue valueWithCGPoint:CGPointMake(0.5f - setting.sideDisplacement, self.view.layer.anchorPoint.y)] forKey:@"anchorPoint"];

if ([setting hasStyle:A_MultipleViewStyleRotate]) {
CATransform3D transform = CATransform3DMakeScale(profileEdgeZoomRate(setting.scaleOfEdge), profileEdgeZoomRate(setting.scaleOfEdge), 1);
CATransform3D transform = CATransform3DMakeScale(profileEdgeZoomRate(setting.scaleOfEdgeX), profileEdgeZoomRate(setting.scaleOfEdgeY), 1);
transform = CATransform3DRotate(transform, -(profileEdgeRotateAngle), 0.0, 1.0, 0);
transform = CATransform3DPerspect(transform, CGPointMake(0, 0), perspectDistance);

[animationSet setObject:[NSValue valueWithCATransform3D:transform] forKey:@"transform"];
// [animationSet setObject:[NSValue valueWithCGPoint:CGPointMake(self.view.layer.position.x + (self.view.layer.bounds.size.width / 2.8), self.view.layer.position.y)] forKey:@"position"];
} else {
[animationSet setObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(setting.scaleOfEdge, setting.scaleOfEdge, 1)] forKey:@"transform"];
[animationSet setObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(setting.scaleOfEdgeX, setting.scaleOfEdgeY, 1)] forKey:@"transform"];
}
}
break;
Expand All @@ -116,7 +116,7 @@ - (NSDictionary *)sideToCenterAttributes: (A_ContainerSetting *)setting directio
NSMutableDictionary *animationSet = [[NSMutableDictionary alloc] init];

[animationSet setObject:[NSValue valueWithCGPoint:CGPointMake(0.5f, self.view.layer.anchorPoint.y)] forKey:@"anchorPoint"];
[animationSet setObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(setting.scaleOfCurrent, setting.scaleOfCurrent, 1)] forKey:@"transform"];
[animationSet setObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(setting.scaleOfCurrentX, setting.scaleOfCurrentY, 1)] forKey:@"transform"];
// [animationSet setObject:[NSValue valueWithCGPoint:self.view.layer.position] forKey:@"position"];

NSDictionary *extraAnimation = [self A_ExtraSideToCenterAnimation:setting direction:direction];
Expand All @@ -141,7 +141,7 @@ - (NSDictionary *)sideToOutAttributes: (A_ContainerSetting *)setting direction:(
default:
break;
}
[animationSet setObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(setting.scaleOfEdge, setting.scaleOfEdge, 1)] forKey:@"transform"];
[animationSet setObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(setting.scaleOfEdgeX, setting.scaleOfEdgeY, 1)] forKey:@"transform"];

NSDictionary *extraAnimation = [self A_ExtraSideToOutAnimation:setting direction:direction];
if (extraAnimation && extraAnimation.count > 0) {
Expand Down
54 changes: 47 additions & 7 deletions A_ViewContainer/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8191" systemVersion="14F27" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8191" systemVersion="15A284" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8154"/>
Expand All @@ -14,29 +14,46 @@
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="414" height="736"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="qub-Td-jcN" customClass="A_MultipleViewContainer">
<rect key="frame" x="20" y="10" width="560" height="510"/>
<rect key="frame" x="20" y="10" width="374" height="646"/>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Huf-iw-Rpz">
<rect key="frame" x="160" y="698" width="94" height="30"/>
<animations/>
<constraints>
<constraint firstAttribute="width" constant="94" id="Hfv-vX-egS"/>
<constraint firstAttribute="height" constant="30" id="LLz-O6-g3M"/>
</constraints>
<state key="normal" title="Next example"/>
<connections>
<segue destination="ZWO-dD-m95" kind="show" id="xON-AJ-6sZ"/>
</connections>
</button>
</subviews>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="qub-Td-jcN" secondAttribute="bottom" constant="80" id="6oD-zD-m84"/>
<constraint firstItem="Huf-iw-Rpz" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="EYj-RL-Lzd"/>
<constraint firstAttribute="trailing" secondItem="qub-Td-jcN" secondAttribute="trailing" constant="20" id="Jlx-jA-qiO"/>
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="Huf-iw-Rpz" secondAttribute="bottom" constant="8" id="Va9-cp-IMQ"/>
<constraint firstItem="qub-Td-jcN" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="top" constant="10" id="igc-lq-REg"/>
<constraint firstItem="qub-Td-jcN" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" constant="20" id="ynt-KY-7K6"/>
</constraints>
</view>
<simulatedScreenMetrics key="simulatedDestinationMetrics" type="retina55"/>
<connections>
<outlet property="centerView" destination="qub-Td-jcN" id="3ux-7P-RX8"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="637" y="294"/>
<point key="canvasLocation" x="841" y="249"/>
</scene>
<!--Demo Label View Controller-->
<scene sceneID="L3V-p1-TCt">
Expand All @@ -47,11 +64,12 @@
<viewControllerLayoutGuide type="bottom" id="XGy-7q-TBm"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="C3h-6u-2Ax">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="414" height="736"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" usesAttributedText="YES" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ulk-y3-Tha">
<rect key="frame" x="266" y="120" width="68" height="21.5"/>
<rect key="frame" x="173" y="120.5" width="68" height="21.5"/>
<animations/>
<attributedString key="attributedText">
<fragment content="Demo X">
<attributes>
Expand All @@ -64,19 +82,41 @@
<nil key="highlightedColor"/>
</label>
</subviews>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="centerX" secondItem="ulk-y3-Tha" secondAttribute="centerX" id="Juo-gl-jOl"/>
<constraint firstItem="ulk-y3-Tha" firstAttribute="top" secondItem="gpf-Pb-K0J" secondAttribute="bottom" constant="100" id="xrF-Ft-ZMG"/>
</constraints>
</view>
<simulatedScreenMetrics key="simulatedDestinationMetrics" type="retina55"/>
<connections>
<outlet property="labelText" destination="ulk-y3-Tha" id="JB9-aC-Xy0"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="DoE-8s-qOr" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1277" y="294"/>
<point key="canvasLocation" x="1317" y="249"/>
</scene>
<!--View Controller Programmatic-->
<scene sceneID="42U-lI-LFp">
<objects>
<viewController id="ZWO-dD-m95" customClass="ViewControllerProgrammatic" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="VA6-kH-J3m"/>
<viewControllerLayoutGuide type="bottom" id="PHr-dK-kEV"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Azr-rC-8Ku">
<rect key="frame" x="0.0" y="0.0" width="414" height="736"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
<simulatedScreenMetrics key="simulatedDestinationMetrics" type="retina55"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Eil-bn-KK0" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1317" y="1133"/>
</scene>
</scenes>
</document>
13 changes: 13 additions & 0 deletions A_ViewContainer/Example/DemoLabelViewControllerShadow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// DemoLabelViewController.h
// A_ViewContainer
//
// Created by Animax Deng on 7/25/15.
// Copyright (c) 2015 Animax Deng. All rights reserved.
//

#import "A_ViewBaseController.h"

@interface DemoLabelViewControllerShadow : A_ViewBaseController

@end
Loading