UIPresentModalViewController view alpha is not being set - iphone

I want to present a view controller where I have one Background imageView.
Alpha for that imageview is 0.5 (want to add as semi-transperant black image so). But when I present that view controller that alpha doesn't work for view. That image entirely looks blackish, like alpha has not been even set.
This issue is there for iPad device only.
Please help me out.
Code:
ViewController1.m:
[self presentModalViewController:viewController2];
ViewController2.xib: (in nib I am setting below values no in code)
[self.view setBackgroundColor:[UIColor clearColor]];
[self.bgImageView setAlpha:0.5]; // this image is dark black, i want to display the
content of the screen which is behind this (viewController1.view), kind of semi-transperancy
I tried one more thing, this time i have removed imageView and set uiview bgcolor to black, opaque=NO, alpha=0.2 (in nib itself). So while animation of presenting it looks perfect. But when view has been placed it turns into alpha=1.0 (complete black)
Still there is no transparency where am i wrong over here.
Answer Is Here: There is some bug/limitation with ModalViewController so its better to go with addSubview for such situation

Try to write imageview.alpha = 0.5 after you present the modelviewcontroller and see what happens. Just give it a try.
EDIT:
1)Clean Build and Run
The image alpha you are trying to set, is it in viewcontroller that you are presenting from or is it in modalviewcontroller?

Answer Is Here: There is some bug/limitation with ModalViewController so its better to go with addSubview for such situation

Related

Xcode warning: "This will cause the effect to appear broken until opacity returns to 1"

I have a prototype cell and I put a UIVisualEffectView inside its ContentView. Visual Effect View's Blur Style is Dark and Vibrancy is off. Then I set the alpha of the Visual Effect View to 0,5 using the IB.
Then on runtime, I get a warning that says:
<UIVisualEffectView ...> is being asked to animate its opacity. This will cause the effect to appear broken until opacity returns to 1.
I couldn't understand why this warning is there and how I can set this alpha property properly.
The question is what do you want to animate. If it's the effect, you cannot animate it via the alpha property. However, since iOS 9, you can animate it with setting the effect in animation block.
UIVisualEffectView* view = [[UIVisualEffectView alloc] initWithFrame:self.view.bounds];
view.effect = nil;
[UIView animateWithDuration:0.3 animations:^{
view.effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
}];
Alternatively, you can animate the effect by animating the alpha of the wrapper view, as proposed in the other answers (working even on iOS 8).
If you want to animate the content of the visual effect view (the subviews), animate the contentView property instead (which you should use to add subviews of the effect view).
[UIView animateWithDuration:0.3 animations:^{
view.contentView.alpha = 1.0;
}];
So to sum up, you should never change alpha of the UIVisualEffectView itself as it's most likely not what you want.
As far as I can remember you cannot change the alpha of a visual effect view. The alpha always has to be one.
The desired effect can be achieved by setting alpha of the background color rather than the Visual Effect View. The subviews should be added to View of Visual Effect View and they are not affected by the background blur.
The Vibrancy effect must be selected in View Effect View options above.
See image:
user1179321 definetely right. According to UIVisualEffectView Documentation;
When using the UIVisualEffectView class, avoid alpha values that are
less than 1. Creating views that are partially transparent causes the
system to combine the view and all the associated subviews during an
offscreen render pass. UIVisualEffectView objects need to be combined
as part of the content they are layered on top of in order to look
correct. Setting the alpha to less than 1 on the visual effect view or
any of its superviews causes many effects to look incorrect or not
show up at all.
https://developer.apple.com/library/ios/documentation/uikit/reference/UIVisualEffectView/index.html
My solution:
Duplicate the layer behind the visual effect view. (In my case an UIImageView)
Animates the alpha value the the duplicated view. (e.g. alpha form 1 to 0, shows the blurred Image)
If u presenting viewcontroller modally, try to disable animation checkbox in segue.
You never know if the delay is long enough; so a bit of a cleaner solution is to just do the presentation in the next run loop.
dispatch_async(dispatch_get_main_queue(), ^(void){
[self presentViewController:yourPopoverr animated: YES completion: nil];
});

UINavigationController - Keep Background Image Across All Views

Is there a way to have a background image remain constant across all views in a navigation controller? Currently I am loading the same background in each view's viewDidLoad method but this shows the background image move when navigating from view to view. I'd rather just the content of the view infront of the background "slide" on/off screen, but the background stay stationary. This is my current background image loading code:
UIImageView *background = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
background.image = [UIImage imageNamed:#"InfoBackground.png"];
[self.view addSubview:background];
[self.view sendSubviewToBack:background];
[background release];
Thanks!
Hm, perhaps if you look at the documentation (scroll down to Figure 2) you will get an idea of what you're dealing with. Because you are setting the background image for each of your view controllers that are being pushed into the UINavigationController, you will get that animation. What you need to do is set the background image into the nav controller itself.
I believe myNavController.view insertSubview:myImageView atIndex:0 should work. If your image needs to fill in behind the content view exactly, you could set the frame coordinates based on the coordinates and/or heights of the navbar and toolbar, which can be accessed through the navigation controller's properties. If not, just set the frame to the superview's bounds.
Let me know how it goes.
Edit: Oh, note that you would need to make sure each of your view controllers had transparent backgrounds.
i think the better idea is place background image on window and set all view's(all viewcontroller's view) background color to clear color [UIColor clearColor].
if you want background image static then there is only one way but i don't know that is possible or not, If we put image in window and make navigation controller transparent then it's stay static whatever you will do. because we are not changing window while push or pop.
I am just suggesting try this way i haven't tried like this.

iOS5 iPhone4 InterfaceBuilder suddenly all of my views have transparency. How to fix?

I have a set of UIViews arranged in layers one over another. I've added another ImageView and added several images to that via imageView.animationImages property. A weird thing happened: all of the sudden, all of my views above the image view have transparency, causing a very glitchy feeling.
Is this a bug, or did I toggle some sort of blending property by accident? I've checked, all the views have alpha set to 1, as expected in the IB.
Thank you for your help!
Solution:
The offending line of code was:
self.tabBar.view.alpha = 0.7;
I was trying to create a transparent tabbar (my navbar is already transparent).
No, it isn't a bug. You have to know when you set transparency in a view, all their subview will have transparency too.
So, you create a superViewand than:
[superView addSubview:view1];
[superView addSubview:view2];
After this, you set
[superView setAlpha:0.0f];
Than view1 and view2 will have their alpha=0.0f
To solve this, you have to create 2 other views in this way:
/ - transparentView
SuperView -
\ / - view1
\ - OtherView -
\ - view2
Than you have the efect you want.

Black corners around UITableViewCells

I am trying to display a UITableView in front of an image, and here's the steps I'm following:
Inside the view, add a UIImageView with the image set to the appropriate file in the project
Add a UITableView inside the parent view (the same parent as the image view)
Set the backgroundColor for the table view to clear
Wire up a datasource in the view controller to display some test data
Hook up the data source in IB.
After doing this, the tableviewcells have a black background in the corners. It isn't coming from any of the parent views as far as I can tell. I have a test project at bitbucket which demonstrates the issue.
Jeff Lamarche ran into the exact same issue today and put up a blog post about it:
http://iphonedevelopment.blogspot.com/2010/08/transparent-grouped-tableviews.html
Basically, there appears to be some bug where you still need to add this in code (even though you already have the tableView set to be clear in Interface Builder):
self.tableView.backgroundColor = [UIColor clearColor];
To remove the black edges just go to ur .m file and in ur viewDidLoad method add a line
tableName.backgroundColor = [UIColor clearColor];
and thats it no more ugly UI
As stated in Jawboxer's answer, you need to set the background colour in code:
self.tableView.backgroundColor = [UIColor clearColor];
But also ensure that the background colour in Interface Builder is set to the default "Group Table View Background Color". I had it as "Clear Color" in IB and it still wasn't working, until I reset it to the default.
The root cause of why you must set the clear color in code is here: Black corners on UITableView Group Style

Navigation Controller Transparent Bar Style is not working

I am using a navigation controller, and I have the style set to :
navController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
But when I run my program, the navigation controller looks like it is on top of a white background, not my background. When I push a controller, left or right, all my view, the current one, shifts to the top exactly the size of the navigation bar. And it is there where I can see my background through the navigation controller bar. Any ideas? When my barStyle is set to opaque, everything looks fine. I was thinking on setting my view frame a negative 'y' value, but I think there should a more elegant way.
I believe the UINavigationController assumes that your controller view frames don't include the area beneath the navigation bar.
UIBarStyleBlackTranslucent is more often used for UIToolbar, so Apple probably didn't make it easy to use it nicely with UINavigationBar. You'll probably need to abandon the UINavigationController, or start hacking the frames (careful with rotations), if you want to reliably render under the bar area.
Also, if your intention is to hide the navigation bar after a few seconds, you'll have a much easier time if you make it fade out (like the Photos app) instead of trying to slide it up (like Mobile Safari). Trust me on that one... that took me a lot of time to learn the hard way.
Simply use a transparent background image, and translucent = YES to allow the content to flow below the bar. Works on iOS 5 / 6. Add in viewDidLoad.
self.navigationController.navigationBar.translucent = YES;
UIImage * backgroundImage = [UIImage imageNamed:#"spacer.gif"];
[self.navigationController.navigationBar setBackgroundImage:(UIImage *)backgroundImage forBarMetrics:UIBarMetricsDefault];
I attached the spacer.gif image here, a single 1px x 1px transparent image.
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.169 green:0.373 blue:0.192 alpha:0.9];
self.navigationController.navigationBar.translucent = YES;
Note:
Don't use self.navigationBarStyle and self.navigationBarTintColor to change.
Add the last two statements to your viewDidLoad.
I ran into this same problem (in 3.1.3) and while you can't set the bar style after the navigationBar has already been setup you CAN set the tintColor and translucent values whenever you like:
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
self.navigationController.navigationBar.translucent = YES;
Will create the 'blackTranslucent' bar, I change the navigationBar look when I push certain view controllers onto the stack.
I had the same problem, and I solved it by making the background of the root view the same as my view. The white area behind the navigation bar turned out to be the root view.
The navigation controller offsets the coordinate sytem of all it's subviews so they draw below the navigation bar.
Extend your view's frame into the negative y domain for it to draw under the navigation bar.
You need to set the barstyle in your info.plist file for it offset everything correctly.
However, I haven't tried it since the 2.1 f/w was released, but when I tried this in 2.0 I found that the setting was lost after a rotation from portrait to landscape.
try to use this, may be it will helpful.
_topToolBar.barStyle = UIBarStyleBlackTranslucent;
_topToolBar.alpha = 0.3;
I had a same problem.I solved!
ImageViewExtendController *detailImageController = [[ImageViewExtendController alloc] init];
[detailImageController loadImage:url];
[self.navigationController pushViewController:detailImageController animated:YES];
If you set your nav controller's navigationBar to transparent in your App delegate early enough (It worked for me before adding the nav controller to the window), it will automatically shift your view up underneath the navigation bar.
Unfortunately it does not also shift your view underneath the status bar. Sad, it looks like you need to implement your own version of UINavigationController. Luckily, it's not too bad as UINavigationBar is pretty reusable.
Try this:
self.tabBarController.tabBar.superview.backgroundColor = [UIColor blackColor];
Change the Extend Edges options in child viewControllers
As for example, in xcode editor, go to your first viewcontroller child and unset the options:
Extend Edges;
Under Top Bars;
Under Bottom Bars;
Under Opaque Bars;
This way your child ViewController will not layout starting below the status bar of the navigation controller, neither the tabbar or the toolbars
hope it may help anyone