Skip to content

Commit 4cdbfae

Browse files
committed
BUGFIX: more correct handling of view.bounds and view.frame
1 parent 974219b commit 4cdbfae

5 files changed

+33
-30
lines changed

FRLayeredNavigationController/FRLayerChromeView.m

+3-3
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@ - (void)layoutSubviews {
111111

112112
CGFloat barButtonItemsSpace = (self.leftBarButtonItem!=nil?44:0) + (self.rightBarButtonItem!=nil?44:0);
113113

114-
self.toolbar.frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height);
114+
self.toolbar.frame = CGRectMake(0, 0, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds));
115115

116116
CGRect headerMiddleFrame = CGRectMake(10 + (barButtonItemsSpace/2),
117117
0,
118-
self.bounds.size.width-20-barButtonItemsSpace,
119-
self.bounds.size.height);
118+
CGRectGetWidth(self.bounds)-20-barButtonItemsSpace,
119+
CGRectGetHeight(self.bounds));
120120

121121
CGSize titleFittingSize = [self.titleView sizeThatFits:headerMiddleFrame.size];
122122
CGRect titleFrame = CGRectMake(MAX((headerMiddleFrame.size.width - titleFittingSize.width)/2,

FRLayeredNavigationController/FRLayerController.m

+7-7
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,23 @@ - (void)doViewLayout {
7575
if (self.layeredNavigationItem.hasChrome) {
7676
CGRect chromeFrame = CGRectMake(0,
7777
0,
78-
self.view.bounds.size.width,
78+
CGRectGetWidth(self.view.bounds),
7979
FRLayerChromeHeight);
8080
CGRect borderFrame = CGRectMake(0,
8181
FRLayerChromeHeight,
82-
self.view.bounds.size.width,
83-
self.view.bounds.size.height-FRLayerChromeHeight);
82+
CGRectGetWidth(self.view.bounds),
83+
CGRectGetHeight(self.view.bounds)-FRLayerChromeHeight);
8484
contentFrame = CGRectMake(1,
8585
FRLayerChromeHeight + 1,
86-
self.view.bounds.size.width-2,
87-
self.view.bounds.size.height-FRLayerChromeHeight-2);
86+
CGRectGetWidth(self.view.bounds)-2,
87+
CGRectGetHeight(self.view.bounds)-FRLayerChromeHeight-2);
8888
self.borderView.frame = borderFrame;
8989
self.chromeView.frame = chromeFrame;
9090
} else {
9191
contentFrame = CGRectMake(0,
9292
0,
93-
self.view.bounds.size.width,
94-
self.view.bounds.size.height);
93+
CGRectGetWidth(self.view.bounds),
94+
CGRectGetHeight(self.view.bounds));
9595
}
9696

9797

FRLayeredNavigationController/FRLayeredNavigationController.m

+20-20
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ - (void)loadView
101101
vc.view.frame = CGRectMake(vc.layeredNavigationItem.currentViewPosition.x,
102102
vc.layeredNavigationItem.currentViewPosition.y,
103103
vc.layeredNavigationItem.width,
104-
self.view.bounds.size.height);
104+
CGRectGetHeight(self.view.bounds));
105105
vc.view.autoresizingMask = UIViewAutoresizingFlexibleHeight;
106106
[self.view addSubview:vc.view];
107107
}
@@ -272,7 +272,7 @@ - (void)viewControllersToSnappingPointsMethod:(SnappingPointsMethod)method {
272272

273273
const CGFloat curDiff = myPos.x - last.layeredNavigationItem.currentViewPosition.x;
274274
const CGFloat initDiff = myInitPos.x - last.layeredNavigationItem.initialViewPosition.x;
275-
const CGFloat maxDiff = last.view.bounds.size.width;
275+
const CGFloat maxDiff = CGRectGetWidth(last.view.frame);
276276

277277
if (xTranslation == 0 && (CGFloatNotEqual(curDiff, initDiff) && CGFloatNotEqual(curDiff, maxDiff))) {
278278
switch (method) {
@@ -333,7 +333,7 @@ - (void)moveViewControllersXTranslation:(CGFloat)xTranslationGesture
333333

334334
const CGPoint myPos = meNavItem.currentViewPosition;
335335
const CGPoint myInitPos = meNavItem.initialViewPosition;
336-
const CGFloat myWidth = me.view.bounds.size.width;
336+
const CGFloat myWidth = CGRectGetWidth(me.view.frame);
337337
CGPoint myNewPos = myPos;
338338

339339
const CGPoint myOldPos = myPos;
@@ -442,11 +442,11 @@ - (void)doLayout {
442442
f.origin = vc.layeredNavigationItem.currentViewPosition;
443443

444444
if (vc.maximumWidth) {
445-
f.size.width = self.view.bounds.size.width - vc.layeredNavigationItem.initialViewPosition.x;
446-
vc.layeredNavigationItem.width = f.size.width;
445+
f.size.width = CGRectGetWidth(self.view.bounds) - vc.layeredNavigationItem.initialViewPosition.x;
446+
vc.layeredNavigationItem.width = CGRectGetWidth(f);
447447
}
448448

449-
f.size.height = self.view.bounds.size.height;
449+
f.size.height = CGRectGetHeight(self.view.bounds);
450450

451451
vc.view.frame = f;
452452
}
@@ -502,10 +502,10 @@ - (void)popViewControllerAnimated:(BOOL)animated
502502

503503
[self.viewControllers removeObject:vc];
504504

505-
CGRect goAwayFrame = CGRectMake(vc.view.frame.origin.x,
505+
CGRect goAwayFrame = CGRectMake(CGRectGetMinX(vc.view.frame),
506506
1024,
507-
vc.view.bounds.size.width,
508-
vc.view.bounds.size.height);
507+
CGRectGetWidth(vc.view.frame),
508+
CGRectGetHeight(vc.view.frame));
509509

510510
void (^completeViewRemoval)(BOOL) = ^(BOOL finished) {
511511
[vc willMoveToParentViewController:nil];
@@ -564,8 +564,8 @@ - (void)pushViewController:(UIViewController *)contentViewController
564564
initWithContentViewController:contentViewController maximumWidth:maxWidth];
565565
const FRLayeredNavigationItem *navItem = newVC.layeredNavigationItem;
566566
const FRLayeredNavigationItem *parentNavItem = anchorViewController.layeredNavigationItem;
567-
const CGFloat overallWidth = self.view.bounds.size.width > 0 ?
568-
self.view.bounds.size.width :
567+
const CGFloat overallWidth = CGRectGetWidth(self.view.bounds) > 0 ?
568+
CGRectGetWidth(self.view.bounds) :
569569
[self getScreenBoundsForCurrentOrientation].size.width;
570570

571571
if (contentViewController.parentViewController.parentViewController == self) {
@@ -601,11 +601,11 @@ - (void)pushViewController:(UIViewController *)contentViewController
601601
CGRect onscreenFrame = CGRectMake(newVC.layeredNavigationItem.currentViewPosition.x,
602602
newVC.layeredNavigationItem.currentViewPosition.y,
603603
width,
604-
self.view.bounds.size.height);
605-
CGRect offscreenFrame = CGRectMake(MAX(1024, onscreenFrame.origin.x),
604+
CGRectGetHeight(self.view.bounds));
605+
CGRect offscreenFrame = CGRectMake(MAX(1024, CGRectGetMinX(onscreenFrame)),
606606
0,
607-
onscreenFrame.size.width,
608-
onscreenFrame.size.height);
607+
CGRectGetWidth(onscreenFrame),
608+
CGRectGetHeight(onscreenFrame));
609609
newVC.view.frame = offscreenFrame;
610610

611611
[self.viewControllers addObject:newVC];
@@ -616,11 +616,11 @@ - (void)pushViewController:(UIViewController *)contentViewController
616616
delay:0
617617
options: UIViewAnimationCurveEaseOut
618618
animations:^{
619-
CGFloat saved = [self savePlaceWanted:onscreenFrame.origin.x+width-overallWidth];
620-
newVC.view.frame = CGRectMake(onscreenFrame.origin.x - saved,
621-
onscreenFrame.origin.y,
622-
onscreenFrame.size.width,
623-
onscreenFrame.size.height);
619+
CGFloat saved = [self savePlaceWanted:CGRectGetMinX(onscreenFrame)+width-overallWidth];
620+
newVC.view.frame = CGRectMake(CGRectGetMinX(onscreenFrame) - saved,
621+
CGRectGetMinY(onscreenFrame),
622+
CGRectGetWidth(onscreenFrame),
623+
CGRectGetHeight(onscreenFrame));
624624
newVC.layeredNavigationItem.currentViewPosition = newVC.view.frame.origin;
625625

626626
}
342 KB
Loading

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ Features
4040
- You can easily install FRLayeredNavigationController using
4141
[CocoaPods](http://cocoapods.org/) or manually (screencast and instructions
4242
below)
43+
- Correctly handles `view.frame` and `view.bounds` and has therefore no
44+
problems with `view.transform` (such as rotations) as you can see on this
45+
[screenshot](https://github.com/weissi/FRLayeredNavigationController/raw/master/FRLayeredNavigationControllerRotation.png).
4346

4447

4548
License

0 commit comments

Comments
 (0)