Browse files

Use flip styles for modal and push transitions. Removed segues from s…

…toryboards (because I want to dynamically switch between fold & flip transitions based on user selection).
  • Loading branch information...
1 parent 04c1d8e commit 0ff79d79d4e28b0203c772c0a89241b11878cf13 Mark Pospesel committed May 16, 2012
View
7 MPFoldTransition/DetailsViewController.h
@@ -1,6 +1,6 @@
//
// DetailsViewController.h
-// MPFoldTransition (v 1.0.0)
+// MPFoldTransition (v 1.1.0)
//
// Created by Mark Pospesel on 4/20/12.
// Copyright (c) 2012 Mark Pospesel. All rights reserved.
@@ -11,6 +11,9 @@
@interface DetailsViewController : UIViewController
-@property (assign, nonatomic) MPFoldStyle style;
+@property (assign, nonatomic, getter = isFold) BOOL fold;
+@property (assign, nonatomic) NSUInteger style;
+
+- (IBAction)popPressed:(id)sender;
@end
View
18 MPFoldTransition/DetailsViewController.m
@@ -1,21 +1,24 @@
//
// DetailsViewController.m
-// MPFoldTransition (v 1.0.0)
+// MPFoldTransition (v 1.1.0)
//
// Created by Mark Pospesel on 4/20/12.
// Copyright (c) 2012 Mark Pospesel. All rights reserved.
//
#import "DetailsViewController.h"
#import "MPFoldSegue.h"
+#import "MPFoldTransition.h"
+#import "MPFlipTransition.h"
@interface DetailsViewController ()
@end
@implementation DetailsViewController
-@synthesize style;
+@synthesize style = _style;
+@synthesize fold = _fold;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
@@ -48,14 +51,23 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
}
}
-- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
+// I removed the segues from the storyboards so that I could switch between flip and fold segue classes
+/*- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue isKindOfClass:[MPFoldSegue class]])
{
MPFoldSegue *foldSegue = (MPFoldSegue *)segue;
// do the opposite fold style from the transition that presented this view
[foldSegue setStyle:MPFoldStyleFlipFoldBit([self style])];
}
+}*/
+
+- (IBAction)popPressed:(id)sender {
+ // do the opposite fold/flip style from the transition that presented this view
+ if ([self isFold])
+ [self.navigationController popViewControllerWithFoldStyle:MPFoldStyleFlipFoldBit([self style])];
+ else
+ [self.navigationController popViewControllerWithFlipStyle:MPFlipStyleFlipDirectionBit([self style])];
}
@end
View
3 MPFoldTransition/ViewController.h
@@ -29,7 +29,8 @@ enum {
- (IBAction)stepperValueChanged:(id)sender;
- (IBAction)stylePressed:(UIBarButtonItem *)sender;
-//- (IBAction)infoPressed:(id)sender;
+- (IBAction)infoPressed:(id)sender;
- (IBAction)modeValueChanged:(id)sender;
+- (IBAction)detailPressed:(id)sender;
@end
View
68 MPFoldTransition/ViewController.m
@@ -14,6 +14,7 @@
#import "DetailsViewController.h"
#define ABOUT_IDENTIFIER @"AboutID"
+#define DETAILS_IDENTIFIER @"DetailsID"
#define ABOUT_SEGUE_IDENTIFIER @"segueToAbout"
#define DETAILS_SEGUE_IDENTIFIER @"segueToDetails"
#define STYLE_TABLE_IDENTIFIER @"StyleTableID"
@@ -179,6 +180,15 @@ - (UILabel *)getLabelForIndex:(NSUInteger)index
return label;
}
+- (void)updateClipsToBounds
+{
+ // We want clipsToBounds == YES on the central contentView when fold style mode bit is not cubic
+ // Otherwise you see the top & bottom panels sliding out and looks weird
+ [self.contentView setClipsToBounds:[self isFold] && (([self foldStyle] & MPFoldStyleCubic) != MPFoldStyleCubic)];
+}
+
+#pragma mark - Touch handlers
+
- (IBAction)stepperValueChanged:(id)sender {
UIStepper *stepper = sender;
[stepper setUserInteractionEnabled:NO];
@@ -218,16 +228,16 @@ - (IBAction)stepperValueChanged:(id)sender {
}
}
-/* Info button is wired to use a storyboard segue,
- but if you wanted to remove the segue and do it in code
- this is how you would do it
- (IBAction)infoPressed:(UIBarButtonItem *)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:[AppDelegate storyboardName] bundle:nil];
AboutViewController *about = [storyboard instantiateViewControllerWithIdentifier:ABOUT_IDENTIFIER];
[about setModalDelegate:self];
- [self presentViewController:about foldStyle:[self style] completion:nil];
-}*/
+ if ([self isFold])
+ [self presentViewController:about foldStyle:[self foldStyle] completion:nil];
+ else
+ [self presentViewController:about flipStyle:[self flipStyle] completion:nil];
+}
- (IBAction)stylePressed:(id)sender {
BOOL isPad = [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad;
@@ -256,6 +266,7 @@ - (IBAction)stylePressed:(id)sender {
}
else
{
+ // for iPad, just use a popover
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:styleTable];
[self setPopover:[[UIPopoverController alloc] initWithContentViewController:navController]];
@@ -264,9 +275,30 @@ - (IBAction)stylePressed:(id)sender {
}
}
+- (IBAction)modeValueChanged:(id)sender {
+ // switch between fold & flip transitions
+ [self setMode:[sender selectedSegmentIndex]];
+ [self updateClipsToBounds];
+}
+
+- (IBAction)detailPressed:(id)sender {
+ BOOL isFold = [self isFold];
+ UIStoryboard *storyboard = [UIStoryboard storyboardWithName:[AppDelegate storyboardName] bundle:nil];
+ DetailsViewController *details = [storyboard instantiateViewControllerWithIdentifier:DETAILS_IDENTIFIER];
+ [details setFold:isFold];
+ [details setStyle:[self style]];
+
+ // push Details view controller onto navigation stack (using a fold or flip transition in our current style!)
+ if (isFold)
+ [self.navigationController pushViewController:details foldStyle:[self foldStyle]];
+ else
+ [self.navigationController pushViewController:details flipStyle:[self flipStyle]];
+}
+
#pragma mark - Storyboards
-- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
+// I removed the segues from the storyboards so that I could switch between flip and fold segue classes
+/*- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// set the selected fold style to our segues
if ([[segue identifier] isEqualToString:DETAILS_SEGUE_IDENTIFIER])
@@ -285,16 +317,24 @@ - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
MPFoldSegue *foldSegue = (MPFoldSegue *)segue;
[foldSegue setStyle:[self foldStyle]];
}
-}
+}*/
#pragma mark - MPModalViewControllerDelegate
- (void)dismiss
{
// use the opposite fold style from the transition that presented the modal view
- MPFoldStyle dismissStyle = MPFoldStyleFlipFoldBit([self foldStyle]);
-
- [self dismissViewControllerWithFoldStyle:dismissStyle completion:nil];
+ if ([self isFold])
+ {
+ MPFoldStyle dismissStyle = MPFoldStyleFlipFoldBit([self foldStyle]);
+
+ [self dismissViewControllerWithFoldStyle:dismissStyle completion:nil];
+ }
+ else
+ {
+ MPFlipStyle dismissStyle = MPFlipStyleFlipDirectionBit([self flipStyle]);
+ [self dismissViewControllerWithFlipStyle:dismissStyle completion:nil];
+ }
}
#pragma mark - UIPopoverControllerDelegate
@@ -309,13 +349,7 @@ - (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverControl
- (void)styleDidChange:(NSUInteger)newStyle
{
[self setStyle:newStyle];
-
- // We want clipsToBounds == YES on the central contentView when mode bit is not cubic
- // Otherwise you see the top & bottom panels sliding out and looks weird
- [self.contentView setClipsToBounds:[self isFold] && ((newStyle & MPFoldStyleCubic) != MPFoldStyleCubic)];
+ [self updateClipsToBounds];
}
-- (IBAction)modeValueChanged:(id)sender {
- [self setMode:[sender selectedSegmentIndex]];
-}
@end
View
48 MPFoldTransition/en.lproj/MainStoryboard_iPad.storyboard
@@ -273,11 +273,11 @@
<placeholder placeholderIdentifier="IBFirstResponder" id="3" sceneMemberID="firstResponder"/>
<viewController id="2" customClass="ViewController" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="5">
- <rect key="frame" x="0.0" y="44" width="768" height="980"/>
+ <rect key="frame" x="0.0" y="64" width="768" height="960"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" id="5Ob-70-sOU">
- <rect key="frame" x="234" y="310" width="300" height="360"/>
+ <rect key="frame" x="234" y="300" width="300" height="360"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<subviews>
<stepper opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" autorepeat="NO" wraps="YES" maximumValue="5" id="WyY-GK-GQe">
@@ -303,7 +303,7 @@
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
<view contentMode="scaleToFill" id="iRq-a8-f58">
- <rect key="frame" x="622" y="897" width="126" height="63"/>
+ <rect key="frame" x="622" y="877" width="126" height="63"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMinY="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="UINavigationController push transition" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" minimumFontSize="10" id="gQ0-1m-xOC">
@@ -325,14 +325,14 @@
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
- <segue destination="bxT-gU-5Wc" kind="custom" identifier="segueToDetails" customClass="MPFoldNavPushSegue" id="kAX-pJ-WBF"/>
+ <action selector="detailPressed:" destination="2" eventType="touchUpInside" id="Nz6-gf-i6W"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
<view contentMode="scaleToFill" id="w5E-ch-Giw">
- <rect key="frame" x="20" y="897" width="80" height="63"/>
+ <rect key="frame" x="20" y="877" width="80" height="63"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="infoDark" showsTouchWhenHighlighted="YES" lineBreakMode="middleTruncation" id="aW8-sm-Dyl">
@@ -347,7 +347,7 @@
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
- <segue destination="EYn-Hh-0XX" kind="custom" identifier="segueToAbout" customClass="MPFoldModalSegue" id="oXY-nq-NhI"/>
+ <action selector="infoPressed:" destination="2" eventType="touchUpInside" id="Fpx-Sd-lhZ"/>
</connections>
</button>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="modal transition" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" minimumFontSize="12" adjustsFontSizeToFit="NO" id="4rN-4q-sqd">
@@ -395,9 +395,9 @@
<scene sceneID="9cG-M1-kYc">
<objects>
<placeholder placeholderIdentifier="IBFirstResponder" id="Zl2-IX-mtX" userLabel="First Responder" sceneMemberID="firstResponder"/>
- <viewController id="bxT-gU-5Wc" customClass="DetailsViewController" sceneMemberID="viewController">
+ <viewController storyboardIdentifier="DetailsID" id="bxT-gU-5Wc" customClass="DetailsViewController" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="tVb-pk-rNV">
- <rect key="frame" x="0.0" y="44" width="768" height="960"/>
+ <rect key="frame" x="0.0" y="64" width="768" height="960"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Details" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="10" id="Z8D-ey-d9F">
@@ -420,7 +420,7 @@
<navigationItem key="navigationItem" title="Detail" id="ii7-rb-cOH">
<barButtonItem key="rightBarButtonItem" title="Pop" style="done" id="l4B-7r-qQG">
<connections>
- <segue destination="2" kind="custom" customClass="MPFoldNavPopSegue" id="quN-c0-zTd"/>
+ <action selector="popPressed:" destination="bxT-gU-5Wc" id="byH-EH-HaE"/>
</connections>
</barButtonItem>
</navigationItem>
@@ -433,9 +433,9 @@
<scene sceneID="nEh-y5-dYk">
<objects>
<placeholder placeholderIdentifier="IBFirstResponder" id="ooE-b9-uiw" userLabel="First Responder" sceneMemberID="firstResponder"/>
- <viewController id="EYn-Hh-0XX" customClass="AboutViewController" sceneMemberID="viewController">
+ <viewController storyboardIdentifier="AboutID" id="EYn-Hh-0XX" customClass="AboutViewController" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Zwm-Dy-fUf">
- <rect key="frame" x="0.0" y="0.0" width="768" height="1004"/>
+ <rect key="frame" x="0.0" y="20" width="768" height="1004"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="dismiss modal transition" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" minimumFontSize="12" adjustsFontSizeToFit="NO" id="YVM-6r-GKz">
@@ -499,32 +499,6 @@
<point key="canvasLocation" x="751" y="747"/>
</scene>
</scenes>
- <classes>
- <class className="AboutViewController" superclassName="UIViewController">
- <source key="sourceIdentifier" type="project" relativePath="./Classes/AboutViewController.h"/>
- <relationships>
- <relationship kind="action" name="donePressed:"/>
- </relationships>
- </class>
- <class className="DetailsViewController" superclassName="UIViewController">
- <source key="sourceIdentifier" type="project" relativePath="./Classes/DetailsViewController.h"/>
- </class>
- <class className="StyleTable" superclassName="UITableViewController">
- <source key="sourceIdentifier" type="project" relativePath="./Classes/StyleTable.h"/>
- <relationships>
- <relationship kind="action" name="donePressed:"/>
- </relationships>
- </class>
- <class className="ViewController" superclassName="UIViewController">
- <source key="sourceIdentifier" type="project" relativePath="./Classes/ViewController.h"/>
- <relationships>
- <relationship kind="action" name="modeValueChanged:"/>
- <relationship kind="action" name="stepperValueChanged:"/>
- <relationship kind="action" name="stylePressed:" candidateClass="UIBarButtonItem"/>
- <relationship kind="outlet" name="contentView" candidateClass="UIView"/>
- </relationships>
- </class>
- </classes>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar" statusBarStyle="blackTranslucent"/>
<simulatedOrientationMetrics key="orientation"/>
View
15 MPFoldTransition/en.lproj/MainStoryboard_iPhone.storyboard
@@ -23,12 +23,12 @@
</connections>
</stepper>
<view contentMode="scaleToFill" id="HSa-mD-uY9">
- <rect key="frame" x="20.5" y="19.5" width="280" height="339"/>
+ <rect key="frame" x="20" y="19" width="280" height="339"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="UIView transition" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="12" adjustsFontSizeToFit="NO" id="aGq-aZ-tEO">
- <rect key="frame" x="113" y="358.5" width="94" height="20"/>
+ <rect key="frame" x="113" y="358" width="94" height="20"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="12"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
@@ -60,7 +60,7 @@
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
- <segue destination="Stx-Bs-S6U" kind="custom" identifier="segueToDetails" customClass="MPFoldNavPushSegue" id="93h-D6-gh8"/>
+ <action selector="detailPressed:" destination="2" eventType="touchUpInside" id="lVt-hD-9z4"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="infoDark" showsTouchWhenHighlighted="YES" lineBreakMode="middleTruncation" id="irK-6J-ykQ">
@@ -75,7 +75,7 @@
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
- <segue destination="gbY-x5-idu" kind="custom" identifier="segueToAbout" customClass="MPFoldModalSegue" id="3SF-wH-eTH"/>
+ <action selector="infoPressed:" destination="2" eventType="touchUpInside" id="fLv-Ok-hqK"/>
</connections>
</button>
</subviews>
@@ -438,7 +438,7 @@
<scene sceneID="Fvd-Pi-0bC">
<objects>
<placeholder placeholderIdentifier="IBFirstResponder" id="TbH-N8-NcU" userLabel="First Responder" sceneMemberID="firstResponder"/>
- <viewController id="Stx-Bs-S6U" customClass="DetailsViewController" sceneMemberID="viewController">
+ <viewController storyboardIdentifier="DetailsID" id="Stx-Bs-S6U" customClass="DetailsViewController" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="6ea-Nw-OwI">
<rect key="frame" x="0.0" y="64" width="320" height="416"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
@@ -463,7 +463,7 @@
<navigationItem key="navigationItem" title="Detail" id="MMq-Dp-ofz">
<barButtonItem key="rightBarButtonItem" title="Pop" style="done" id="bqs-Av-y2q">
<connections>
- <segue destination="2" kind="custom" customClass="MPFoldNavPopSegue" id="9Q5-iv-Qba"/>
+ <action selector="popPressed:" destination="Stx-Bs-S6U" id="sNY-4G-xqU"/>
</connections>
</barButtonItem>
</navigationItem>
@@ -493,7 +493,4 @@
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination"/>
</simulatedMetricsContainer>
- <inferredMetricsTieBreakers>
- <segue reference="t5h-7B-TFS"/>
- </inferredMetricsTieBreakers>
</document>

0 comments on commit 0ff79d7

Please sign in to comment.