In a split-view-based iPad app I'm using a custom background image in my navigation bars and toolbars.
I subclassed UINavigationBar
and/or UIToolbar
and in drawRect:
I have (background-image is rectangular):
- (void)drawRect:(CGRect)rect {
CGContextRef c = UIGraphicsGetCurrentContext();
UIImage *image = [UIImage imageNamed:@"background-image"];
CGContextDrawImage(c, rect, image.CGImage);
}
Result is
from which I want to remove rounded corners.What I've tried already:
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
the same result as above,clipsToBounds = YES;
in my subclasses,cornerRadius=0.0
,- iPhoneOS SDK - Remove Corner Rounding from views (iPad problem)
Problem described in 4. is ex开发者_如何学Cactly the same one I'm having. Unfortunately solution described in that question doesn't work for me. When called from viewWillAppear
In Portrait orientation, it hides my navigationItem for some reason. When called from didRotateFromInterfaceOrientation:
in Landscape, rounded corners are gone, but at the same time all user interaction is disabled. Additionaly, when rotated back to Portrait, my "Master" view (left hand-side of the split view) is not hidden.
The output that I got using the code from the accepted answer is:
aView: <UIWindow: 0x5e18470; frame = (0 0; 768 1024); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x5e18280>>
subview: <UILayoutContainerView: 0x6942000; frame = (20 0; 748 1024); transform = [0, -1, 1, 0, 0, 0]; autoresize = W+H; layer = <CALayer: 0x6946b30>>
aView: <UILayoutContainerView: 0x6942000; frame = (20 0; 748 1024); transform = [0, -1, 1, 0, 0, 0]; autoresize = W+H; layer = <CALayer: 0x6946b30>>
subview: <BackgroundImageView: 0xbbacf70; frame = (0 0; 768 1004); layer = <CALayer: 0xbbad020>>
aView: <BackgroundImageView: 0xbbacf70; frame = (0 0; 768 1004); layer = <CALayer: 0xbbad020>>
subview: <UILayoutContainerView: 0x69144e0; frame = (321 0; 703 748); clipsToBounds = YES; layer = <CALayer: 0x6946fe0>>
aView: <UILayoutContainerView: 0x69144e0; frame = (321 0; 703 748); clipsToBounds = YES; layer = <CALayer: 0x6946fe0>>
subview: <UILayoutContainerView: 0xbbabc40; frame = (0 0; 320 748); clipsToBounds = YES; layer = <CALayer: 0xbbabc90>>
aView: <UILayoutContainerView: 0xbbabc40; frame = (0 0; 320 748); clipsToBounds = YES; layer = <CALayer: 0xbbabc90>>
subview: <UIImageView: 0x5e178c0; frame = (321 0; 3 3); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xba60d10>> - (null)
aView: <UIImageView: 0x5e178c0; frame = (321 0; 3 3); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xba60d10>> - (null)
subview: <UIImageView: 0xba74010; frame = (317 0; 3 3); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xba62180>> - (null)
aView: <UIImageView: 0xba74010; frame = (317 0; 3 3); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xba62180>> - (null)
subview: <UIImageView: 0xbad0110; frame = (321 745; 3 3); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xba60da0>> - (null)
aView: <UIImageView: 0xbad0110; frame = (321 745; 3 3); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xba60da0>> - (null)
subview: <UIImageView: 0xba60e00; frame = (317 745; 3 3); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xba60e30>> - (null)
aView: <UIImageView: 0xba60e00; frame = (317 745; 3 3); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xba60e30>> - (null)
And quite right there are small, 3x3px, rounded UIImageViews with corners.
Question is: how do I get rid of those tiny rounded corners?
Solution that worked for me:
- (void)hideSplitViewCorners {
// Hide corners of splitview.
NSMutableArray *views = [NSMutableArray array];
[views addObject:[self view]];
for (NSUInteger i = 0; i < views.count; ++i) {
UIView *view = [views objectAtIndex:i];
[views addObjectsFromArray:view.subviews];
if (view.frame.size.width == 3.0 && view.frame.size.height == 3.0) {
view.hidden = YES;
}
}
}
I call it in loadView
and didRotateFromInterfaceOrientation:
of my subclass of UISplitViewController
.
Note that in the latter I needed to use [self performSelector:@selector(hideSplitViewCorners) withObject:NULL afterDelay:0];
.
Basically, one needs to make sure that hiding of those corners are done after they're already displayed on the screen.
精彩评论