From 78df3bf4b8eb6c3ae006662132b53fe8c8d23316 Mon Sep 17 00:00:00 2001 From: Thijs Scheepers Date: Fri, 29 Aug 2014 10:25:18 +0200 Subject: [PATCH 1/2] Added landscape --- IVPhoneView/IVAppDelegate.m | 8 ++++++-- IVPhoneView/IVPhoneView.h | 10 ++++++++++ IVPhoneView/IVPhoneView.m | 32 ++++++++++++++++++++++++-------- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/IVPhoneView/IVAppDelegate.m b/IVPhoneView/IVAppDelegate.m index 690418e..68e5d6c 100644 --- a/IVPhoneView/IVAppDelegate.m +++ b/IVPhoneView/IVAppDelegate.m @@ -20,8 +20,12 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( UIViewController *viewController = [UIViewController new]; [self.window setRootViewController:viewController]; - IVPhoneView *phoneView = [[IVPhoneView alloc] initWithFrame:CGRectMake(80, 120, 160, 335)]; - [viewController.view addSubview:phoneView]; + IVPhoneView *portraitPhoneView = [[IVPhoneView alloc] initWithFrame:CGRectMake(80, 210, 160, 335)]; + [viewController.view addSubview:portraitPhoneView]; + + IVPhoneView *landscapePhoneView = [[IVPhoneView alloc] initWithFrame:CGRectMake(-7, 30, 335, 160)]; + landscapePhoneView.orientation = IVPhoneViewOrientationLandscape; + [viewController.view addSubview:landscapePhoneView]; [self.window makeKeyAndVisible]; return YES; diff --git a/IVPhoneView/IVPhoneView.h b/IVPhoneView/IVPhoneView.h index 341b9ba..5add867 100644 --- a/IVPhoneView/IVPhoneView.h +++ b/IVPhoneView/IVPhoneView.h @@ -7,11 +7,21 @@ #import +typedef NS_ENUM(NSUInteger, IVPhoneViewOrientation) { + IVPhoneViewOrientationPortrait = 0, + IVPhoneViewOrientationLandscape = 1 +}; + /** * View with a nice iPhone container. Use it to display something within an iPhone graphic. */ @interface IVPhoneView : UIView +/** + * Orientation of the phone view, landscape or portrait + */ +@property (readwrite, nonatomic) IVPhoneViewOrientation orientation; + /** * Set this property to display a view within the phone * Setting will also add to subviews diff --git a/IVPhoneView/IVPhoneView.m b/IVPhoneView/IVPhoneView.m index 6e92b7f..2d5b46c 100644 --- a/IVPhoneView/IVPhoneView.m +++ b/IVPhoneView/IVPhoneView.m @@ -6,6 +6,9 @@ // #import "IVPhoneView.h" +#import + +#define radians(degrees) (degrees * M_PI/180) @implementation IVPhoneView @@ -16,12 +19,14 @@ - (id)initWithFrame:(CGRect)frame if (self) { self.backgroundColor = [UIColor clearColor]; - self.buttonColor = [UIColor colorWithRed: 0.643 green: 0.643 blue: 0.643 alpha: 1]; - self.phoneColor = [UIColor blackColor]; + _buttonColor = [UIColor colorWithRed: 0.643 green: 0.643 blue: 0.643 alpha: 1]; + _phoneColor = [UIColor blackColor]; + + _sideBezzel = 10; + _topBezzel = 45; + _cameraDimentions = 7; - self.sideBezzel = 10; - self.topBezzel = 45; - self.cameraDimentions = 7; + _orientation = IVPhoneViewOrientationPortrait; } return self; @@ -83,9 +88,20 @@ - (void)layoutSubviews - (void)drawRect:(CGRect)rect { - [self drawPhoneWithScreenWidth:rect.size.width - self.sideBezzel * 2.25 - screenHeight:rect.size.height - self.sideBezzel * 0.25 - self.topBezzel * 2 - sideBezzel:self.sideBezzel topBezzel:self.topBezzel cameraDimention:self.cameraDimentions]; + if (self.orientation == IVPhoneViewOrientationLandscape) { + CGContextRef context = UIGraphicsGetCurrentContext(); + + CGContextRotateCTM( context, radians(90)); + CGContextTranslateCTM( context, 0, -rect.size.width ); + + [self drawPhoneWithScreenWidth:rect.size.height - self.sideBezzel * 2.25 + screenHeight:rect.size.width - self.sideBezzel * 0.25 - self.topBezzel * 2 + sideBezzel:self.sideBezzel topBezzel:self.topBezzel cameraDimention:self.cameraDimentions]; + } else { + [self drawPhoneWithScreenWidth:rect.size.width - self.sideBezzel * 2.25 + screenHeight:rect.size.height - self.sideBezzel * 0.25 - self.topBezzel * 2 + sideBezzel:self.sideBezzel topBezzel:self.topBezzel cameraDimention:self.cameraDimentions]; + } } // From PaintCode From bf1ed79cc8938032118aed90db2de25171208ad8 Mon Sep 17 00:00:00 2001 From: Thijs Scheepers Date: Fri, 29 Aug 2014 10:26:50 +0200 Subject: [PATCH 2/2] Updated readme --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 5b30595..5ad3931 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,11 @@ Usage ```objective-c IVPhoneView *phoneView = [[IVPhoneView alloc] initWithFrame:CGRectMake(80, 120, 160, 335)]; [phoneView setViewInPhone:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myScreenshot"]]]; +``` +```objective-c +IVPhoneView *landscapePhoneView = [[IVPhoneView alloc] initWithFrame:CGRectMake(-7, 30, 335, 160)]; +landscapePhoneView.orientation = IVPhoneViewOrientationLandscape; ``` License