Custom Navbar titleView size issue when pushing next ViewController - ios

I'm trying to have a custom titleView for Iphone app iOS 5.0+ . So I placed a graphic like this :
UIView *customTitleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 104, 72)];
UIImageView *customTitleGraphics = [[UIImageView alloc] initWithImage:image];
[customTitleGraphics setTag:kNavigationImageView];
CGRect myFrame = customTitleGraphics.frame;
myFrame.origin.y = 15.0;
myFrame.origin.x = -3.0;
customTitleGraphics.frame = myFrame;
[customTitleView addSubview:customTitleGraphics];
navigationItem.titleView = customTitleView;
And It works so far. The problem i Have is when I try to push another viewController: It looks like the titleView get cut off suddenly when the animation starts.
https://www.dropbox.com/s/0ysiroxayfld1l3/titleview.mov?v=1mci
Do you have any idea where I'm wrong?

I think that the title view is resized by the UINavigationBar when you push the new VC to the navigation stack. What I would suggest would be to prevent the navigation view from clipping to bounds…

Related

Modified navigationbar causes issues on button item

In our project we wanted to change the size of navigationbar. Have achieved it with
#implementation UINavigationBar (customNav)
- (CGSize)sizeThatFits:(CGSize)size {
return CGSizeMake(self.superview.bounds.size.width, 55.0f);
}
#end
But the problem here is.. as you would see go button is little down from screen edge. But I wanted it to be in ultimate corner of screen. I use backgroundColor:, setTitle:forState:methods for constructing look of go button. also back button to be vertically middle. How can I achieve that. Tried Using edgeInsets: but no hope.
Edit: Go button height is 10px less than barheight.
if I give equal height. Below is the result
in somewhat I have tried your coding.Check that
UIButton *goBtn = [UIButton buttonWithType:UIButtonTypeCustom];
goBtn.frame = CGRectMake(0, 0, 63, 80);
goBtn.backgroundColor = [UIColor redColor];
UIView *goButtonView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 63, 50)];
NSLog(#"goButtonView bounds are - %#", NSStringFromCGRect([goButtonView bounds]));
goButtonView.bounds = CGRectOffset(goButtonView.bounds, -17, 0);
NSLog(#"goButtonView bounds are - %#", NSStringFromCGRect([goButtonView bounds]));
[goButtonView addSubview:goBtn];
UIBarButtonItem *goButton = [[UIBarButtonItem alloc] initWithCustomView:goButtonView];
self.navigationItem.rightBarButtonItem = goButton;
Below the references
Issue with button on the left side of the uinavigation bar
UINavigationBar UIBarButtonItems much larger click area than required

Google Maps iOS SDK - Add GMSPanoramaView in a SubView

I'm trying to add a GMSPanoramaView to a SubView.
Here is the code I'm working on :
panoView_ = [[GMSPanoramaView alloc] initWithFrame:CGRectZero];
panoView_.delegate = self;
self.view = panoView_;
[panoView_ moveNearCoordinate:CLLocationCoordinate2DMake(emplLatitude, emplLongitude)];
This code renders the panorama on fullscreen mode.
If I try this, nothing happens :
self.myView = panoView_;
Where myView outlet is set in my storyboard.
This stack is a possible duplicate of this one which never got answered.
Help appreciated :)
Works when panoView_ is NOT inited with CGRectZero
panoView_ = [[GMSPanoramaView alloc] initWithFrame:CGRectMake(200, 200, 400, 400)];
self.myView.frame = panoView_.frame;
[self.myView addSubview:panoView_];
I have had similar issues in the past.
Usually by setting the frame of the panoView_ to be that of the subview, it has worked for me:
self.myView.frame = panoView_.frame;
If that doesn't work, try checking to see if the panoView_ is in the subview's view hierarchy:
NSLog(#"%#", self.myView.subviews);
You can then try adding it as a subview if needed:
[self.myView addSubview:panoView_];

iOS 8 Transparent View with non-transparent subviews

I want to place non transparent content on top of a UIImageView. So I have a view with a transparent background which contains all the content. And I've placed it on top of imageview. I've set this view's background color to clearColor but still I can not get the desired effect.
This was clearly possible with iOS 6 SDK , but now I'm trying with iOS 8 SDK which does not give me what I want.
Check this app's screenshot
I'm trying to achieve similar effect (a semi transparent view) with iOS 8 SDK. However I need to set opacity very low value which makes the view almost transparent. All I could achieve was very little transparency (something like alpha 0.9 even I set 0 ).
This can be achieved by Using UIVisualEffect and UIVisualEffectView which are available from iOS 8 on.
This will provide a transparent view, as you said, without affecting the subviews.
Try this
UIVisualEffectView *blurredView =[[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
[blurredView addSubview:self.mySubView];
and you can add your subviews and image views as well.
Add your required views in the order, similar to the below code...
UIImageView* bottomImgView = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
bottomImgView.image=[UIImage imageNamed:#"yourImg.png"];
[self.view bottomImgView];
UIView* topTransparentView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
topTransparentView.backgroundColor = [UIColor clearColor];
[bottomImgView addSubview:topTransparentView];
UIView* subView = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
subView.backgroundColor = [UIColor blueColor];
[topTransparentView addSubview:subView];

How to show UIButton almost out of modalviewcontroller

I'm trying to create modalviewcontroller, which should look like this
My problem is in the close button. As you can see in this example it almost out of uiview.
I was tried uiview, who has close button, make transparent but when modalview opens it's still in light gray color.
There is bit of my code :
Settings *new = [[Settings alloc]init];
new.modalPresentationStyle = UIModalPresentationFormSheet;
//i was change to other presentation styles, but that no I want.
new.view.backgroundColor = [UIColor clearColor];
[self presentModalViewController:new animated:YES];
CGRect r = CGRectMake(self.view.center.x - 327,
self.view.center.y - 255,
630, 490);
r = [self.view convertRect:r toView:new.view.superview.superview];
new.view.superview.frame = r;
If you still don't understand, what I want there is ilustration of modal view I need:
What is your suggestion, how can I make it?

iOS 7 Translucent Modal View Controller

The App Store app on iOS 7 uses a frosted glass-type effect where it is possible to see the view behind. Is this using an API built into iOS 7 or is it custom code. I was hoping it would be the former but I can't see any obvious references in the documentation. Obvious things like (like setting the alpha property on the modal view) don't seem to have any effect.
To see an example, open the App Store app and press the button at the top-right.
With the release of iOS 8.0, there is no need for getting an image and blurring it anymore. As Andrew Plummer pointed out, you can use UIVisualEffectView with UIBlurEffect.
UIViewController * contributeViewController = [[UIViewController alloc] init];
UIBlurEffect * blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *beView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
beView.frame = self.view.bounds;
contributeViewController.view.frame = self.view.bounds;
contributeViewController.view.backgroundColor = [UIColor clearColor];
[contributeViewController.view insertSubview:beView atIndex:0];
contributeViewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:contributeViewController animated:YES completion:nil];
Solution that works before iOS 8
I would like to extend on rckoenes' answer:
As emphasised, you can create this effect by:
Convert the underlying UIView to an UIImage
Blur the UIImage
Set the UIImage as background of your view.
Sounds like a lot of work, but is actually done pretty straight-forward:
1. Create a category of UIView and add the following method:
-(UIImage *)convertViewToImage
{
UIGraphicsBeginImageContext(self.bounds.size);
[self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
2. Make an image of the current view and blur it by using Apple's Image Effect category (download)
UIImage* imageOfUnderlyingView = [self.view convertViewToImage];
imageOfUnderlyingView = [imageOfUnderlyingView applyBlurWithRadius:20
tintColor:[UIColor colorWithWhite:1.0 alpha:0.2]
saturationDeltaFactor:1.3
maskImage:nil];
3. Set it as background of your overlay.
-(void)viewDidLoad
{
self.view.backgroundColor = [UIColor clearColor];
UIImageView* backView = [[UIImageView alloc] initWithFrame:self.view.frame];
backView.image = imageOfUnderlyingView;
backView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6];
[self.view addSubview:backView];
}
Just reimplemented Sebastian Hojas' solution in Swift:
1. Create a UIView extension and add the following method:
extension UIView {
func convertViewToImage() -> UIImage{
UIGraphicsBeginImageContext(self.bounds.size);
self.drawViewHierarchyInRect(self.bounds, afterScreenUpdates: true)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext();
return image;
}
}
2. Make an image of the current view and blur it by using Apple's Image Effect (I found a reimplementation of this in Swift here: SwiftUIImageEffects
var imageOfUnderlyingView = self.view.convertViewToImage()
imageOfUnderlyingView = imageOfUnderlyingView.applyBlurWithRadius(2, tintColor: UIColor(white: 0.0, alpha: 0.5), saturationDeltaFactor: 1.0, maskImage: nil)!
3. Set it as background of your overlay.
let backView = UIImageView(frame: self.view.frame)
backView.image = imageOfUnderlyingView
backView.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.5)
view.addSubview(backView)
I think this is the easiest solution for a modal view controller that overlays everything with a nice blur (iOS8)
UIViewController * contributeViewController = [[UIViewController alloc] init];
UIBlurEffect * blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *beView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
beView.frame = self.view.bounds;
contributeViewController.view.frame = self.view.bounds;
contributeViewController.view.backgroundColor = [UIColor clearColor];
[contributeViewController.view insertSubview:beView atIndex:0];
contributeViewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:contributeViewController animated:YES completion:nil];
There is no API available in the iOS 7 SDK which will allow you to "frost" the underlaying view controller.
What I have done is render the underlaying view to an image, which I then frosted and set that as background the the view that is being presented.
Apple provides a good example for this: https://developer.apple.com/downloads/index.action?name=WWDC%202013
The project you want is called, iOS_RunningWithASnap
A little simplier way to achieve this (based on Andrew Plummer's answer) with Interface Builder (also it removes side effect that appears in Andrews answer):
In IB add Visual Effect View to your View Controller under your other views;
Make top, bottom, left, right constraints from Visual Effect View to top (parent) View, set all of them to 0;
Set Blur Style;
Add the code where you present your new fancy View Controller:
UIViewController *fancyViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"yourStoryboardIDFOrViewController"];
fancyViewController.view.backgroundColor = [UIColor clearColor];
fancyViewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:fancyViewController
animated:YES
completion:nil];
Actually, the second and third lines are VERY important - otherwise controller will blink and then turn black.
Since iOS 8, this works:
let vc = UIViewController()
vc.view = UIVisualEffectView(effect: UIBlurEffect(style: .Light))
vc.modalPresentationStyle = .OverFullScreen
let nc = UINavigationController(rootViewController: vc)
nc.modalPresentationStyle = .OverFullScreen
presentViewController(nc, animated: true, completion: nil)
The key is the .OverFullScreen flag and ensuring the viewControllers have a blur UIVisualEffectView that is the first visible view.
As #rckoenes said, there is no Apple provided framework to get that effect. But some people out there already built good alternatives, like this one for example:
https://github.com/JagCesar/iOS-blur/
A couple of alternative approaches that also work on iOS 5 and 6:
FXBlurView: https://github.com/nicklockwood/FXBlurView
iOS RealtimeBlur: https://github.com/alexdrone/ios-realtimeblur
Fast & easy solution
with XIB support you can use for the old school boys
https://github.com/cezarywojcik/CWPopup
Instead of presenting the viewController as a modalView, you could add it as a child viewController and create a custom animation. You would then only need to change the default view of the viewController to a UIToolBar in viewDidLoad.
This will allow you to mimic the appstore's blurred modal view as closely as possible.
I have uploaded my take of the blurred view controller to [GitHub][1]. It also comes with a segue subclass so you can use it in your storyboards.
Repository: https://github.com/datinc/DATBlurSegue
Apple released the UIImageEffect category for those effects. Those category should be added manually to the project, and it support iOS7.
You can use UIToolbar as background.
By default UIToolbar have 50px height.
Add auto layout constraints on UIToolbar.
Then select height constraint and modify it.
Hierarchy will look like this:
UIView -> clear colour for background.
- UIToolbar
- Other contents.

Resources