Skip to content

Instantly share code, notes, and snippets.

@dannygreg
Forked from hatfinch/gist:1385399
Created November 22, 2011 12:08

Revisions

  1. Danny Greg revised this gist Nov 22, 2011. 1 changed file with 44 additions and 25 deletions.
    69 changes: 44 additions & 25 deletions gistfile1.m
    Original file line number Diff line number Diff line change
    @@ -1,32 +1,51 @@
    // In the class continuation or private category
    {
    UIView *_portraitView;
    UIView *_landscapeView;
    }
    @property (nonatomic, readonly) UIView *portraitView;
    @property (nonatomic, readonly) UIView *landscapeView;

    - (UIView *)subViewForOritentation:(UIInterfaceOrientation)orientation;

    //In the main @implementation

    - (UIView *)subViewForOritentation:(UIInterfaceOrientation)orientation
    {
    return (orientation == UIInterfaceOrientationPortrait ? self.portraitView : self.landscapeView);
    }

    - (UIView *)portraitView
    {
    if (_portraitView == nil) {
    _portraitView = [[UIView alloc] init];
    //Any setup could go here or a common method if it can be abstracted
    }

    return _portraitView;
    }

    - (UIView *)landscapeView
    {
    if (_landscapeView == nil) {
    _landscapeView = [[UIView alloc] init];
    //Any setup could go here or a common method if it can be abstracted
    }

    return _landscapeView;
    }

    - (void)performLayout
    {
    [super performLayout];

    myScrubView.frame = self.bounds;
    __block BOOL reload = NO;

    UIView (^addSubView)(UIView *) = ^ (UIView *subview) {
    subview.alpha = 0.0;
    if (subview != nil)
    subview.alpha = 1.0;
    else
    {
    subview = [[UIView alloc] init];
    [myScrubView addSubview:subview];
    reload = YES;
    }
    subview.frame = myScrubView.bounds;
    return subview;
    };

    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
    UIView *subView = addSubView(orientation == UIInterfaceOrientationPortrait ? myPortraitView : myLandscapeView);
    if (orientation == UIInterfaceOrientationPortrait) {
    myPortraitView = subView;
    } else {
    myLandscapeView = subView;
    }

    if (reload)
    [self reloadData];
    }
    UIView *subview = [self subViewForOritentation:orientation];
    subview.alpha = 1.0;
    [[[myScrubView subviews] lastObject] removeFromSuperView];
    [myScrubView addSubView:subview];
    subview.frame = myScrubView.bounds;
    [self reloadData];
    }
  2. Danny Greg revised this gist Nov 22, 2011. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions gistfile1.m
    Original file line number Diff line number Diff line change
    @@ -16,6 +16,7 @@ - (void)performLayout
    reload = YES;
    }
    subview.frame = myScrubView.bounds;
    return subview;
    };

    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
  3. Danny Greg revised this gist Nov 22, 2011. 1 changed file with 7 additions and 2 deletions.
    9 changes: 7 additions & 2 deletions gistfile1.m
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ - (void)performLayout
    myScrubView.frame = self.bounds;
    __block BOOL reload = NO;

    void (^addSubView)(UIView *) = ^ (UIView *subview) {
    UIView (^addSubView)(UIView *) = ^ (UIView *subview) {
    subview.alpha = 0.0;
    if (subview != nil)
    subview.alpha = 1.0;
    @@ -19,7 +19,12 @@ - (void)performLayout
    };

    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
    addSubView(orientation == UIInterfaceOrientationPortrait ? myPortraitView : myLandscapeView);
    UIView *subView = addSubView(orientation == UIInterfaceOrientationPortrait ? myPortraitView : myLandscapeView);
    if (orientation == UIInterfaceOrientationPortrait) {
    myPortraitView = subView;
    } else {
    myLandscapeView = subView;
    }

    if (reload)
    [self reloadData];
  4. Danny Greg revised this gist Nov 22, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.m
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@ - (void)performLayout
    [super performLayout];

    myScrubView.frame = self.bounds;
    BOOL reload = NO;
    __block BOOL reload = NO;

    void (^addSubView)(UIView *) = ^ (UIView *subview) {
    subview.alpha = 0.0;
  5. Danny Greg revised this gist Nov 22, 2011. 1 changed file with 13 additions and 25 deletions.
    38 changes: 13 additions & 25 deletions gistfile1.m
    Original file line number Diff line number Diff line change
    @@ -1,37 +1,25 @@
    - (void)performLayout
    {
    [super performLayout];

    myScrubView.frame = self.bounds;
    BOOL reload = NO;

    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
    if (orientation == UIInterfaceOrientationPortrait)
    {
    myLandscapeView.alpha = 0.0;
    if (myPortraitView)
    myPortraitView.alpha = 1.0;
    else
    {
    myPortraitView = [[UIView alloc] init];
    [myScrubView addSubview:myPortraitView];
    reload = YES;
    }
    myPortraitView.frame = myScrubView.bounds;
    }
    else
    {
    myPortraitView.alpha = 0.0;
    if (myLandscapeView)
    myLandscapeView.alpha = 1.0;

    void (^addSubView)(UIView *) = ^ (UIView *subview) {
    subview.alpha = 0.0;
    if (subview != nil)
    subview.alpha = 1.0;
    else
    {
    myLandscapeView = [[UIView alloc] init];
    [myScrubView addSubview:myLandscapeView];
    subview = [[UIView alloc] init];
    [myScrubView addSubview:subview];
    reload = YES;
    }
    myLandscapeView.frame = myScrubView.bounds;
    }
    subview.frame = myScrubView.bounds;
    };

    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
    addSubView(orientation == UIInterfaceOrientationPortrait ? myPortraitView : myLandscapeView);

    if (reload)
    [self reloadData];
  6. @hatfinch hatfinch created this gist Nov 22, 2011.
    38 changes: 38 additions & 0 deletions gistfile1.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    - (void)performLayout
    {
    [super performLayout];

    myScrubView.frame = self.bounds;
    BOOL reload = NO;

    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
    if (orientation == UIInterfaceOrientationPortrait)
    {
    myLandscapeView.alpha = 0.0;
    if (myPortraitView)
    myPortraitView.alpha = 1.0;
    else
    {
    myPortraitView = [[UIView alloc] init];
    [myScrubView addSubview:myPortraitView];
    reload = YES;
    }
    myPortraitView.frame = myScrubView.bounds;
    }
    else
    {
    myPortraitView.alpha = 0.0;
    if (myLandscapeView)
    myLandscapeView.alpha = 1.0;
    else
    {
    myLandscapeView = [[UIView alloc] init];
    [myScrubView addSubview:myLandscapeView];
    reload = YES;
    }
    myLandscapeView.frame = myScrubView.bounds;
    }

    if (reload)
    [self reloadData];
    }