UIView with transparent background flickers on presentation - iphone

I've got really simple view controller that does this in its init:
self.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.65];
When the view is added as a subview of a view that's already on screen, it's background flickers black (ignores the alpha) and then back to the proper color (with alpha). No flicker occurs when alpha is 0 (no surprise) or 1 (no surprise). Note that I'm not touching the alpha or opacity properties on the view or layer as that would cause all the subviews to be transparent also.
Any thoughts on how to fix the flicker?

Instead of changing the backgroundColor in your view controller's init, I would put that line of code in your view controller's viewDidLoad: method. That might fix the 'flickering'.

Related

UIView background color affects touches in iOS 5

I had a custom view with subclassed touch responses that was working in iOS 4. On iOS 5, these touches would not respond at all when touched along the bottom edge of the view, if the view's background color was set to clearColor.
I have not been able to track this down, but does anyone know if iOS 5 changed the way views respond to touches depending on a transparent background?
I can make no changes to the code other than set the background color to any opaque color like orangeColor and the view fully responds.
Note the issue does not affect touches elsewhere in the view; only along the bottom edge, anywhere below the last subview added to the view; presumably a clear background is treated as if the view does not exist for the sake of touches when looking at an area of the view that has no content. Change the color, the view has "content" and the touches work!
Instead of using [UIColor clearColor], try using this:
[view setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.1]];
NOTE: A UIView does not respond to touch events when the alpha is anything below 0.1. [UIColor clearColor] sets an alpha to 0.0, so you won't get the touch events. Following the above method, you can receive the touch events on a transparent view.
In case anyone else runs into this problem and wants a better solution than setting a partial opacity for the background, you can set the view's opaque property to NO and then add an empty drawRect: method. (Tested and working on iOS8, beta 4.)

UIPresentModalViewController view alpha is not being set

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

UITapGestureRecognizer on transparent view

I have a tree with views where the highest level view is transparent and contains either an image or a label (with a transparent background).
When attaching a UITapGestureRecognizer to this view, I only get notifications on the views which contain images.Also, if I leave the view empty, then I get events only when the background color is different than [UIColor clearColor].
I have done a dump and the entire view tree has userInteractionEnable = YES.
How can I get the UITapGesturerRecognizer to work on the view with a transparent background?
Solved
Problem was not what I thought. The transparent views were in a scroll view and during initialization they were outside of the view's visible area. Those within the visible area work ok.
Wild guesses here, but if you include a 1x1 pixel image in the view, would that view then qualify for gestures?
Another equally wild guess would be to add a transparent image to the view and try that.
Try giving the view a nearly-transparent background color, like [UIColor colorWithWhite:0 alpha:0.01].
Try setting the background color to whatever except the clearColor and setting the alpha property to 0.0;
myView.backgroundColor = [UIColor blackColor];
myView.alpha = 0.0;

Layering UIViews so that bottom most layer can be seen

I have a UIView to which i add a background image. Then to that view i add a scroll view. To the scroll view i add some UIButtons.
I would like to be able to set the scroll view to be transparent (still being able to see the UIButtons) so that i can see the background image underneath it, so that it shows between the buttons.
I have tried setting the scrollview background to [UIColor clearColor] but this doesnt work.
Thanks.
In addition to setting the backgroundColor to [UIColor clearColor], you also have to set
scrollView.opaque = NO;
Change the UIScrollView.alpha level to 0.0f

Is there a way to fix the background image of a UITableView

I have set the background of my UITable with a custom image.
self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"background.png"]];
The problem I'm having is the background image is scrolling and doesn't look good at the top and bottom of the screen where you see the image being joined.
Is there a way to fix the position of the background image and just have the table scroll over the top of it?
Insert a UIImageView behind the UITableView. Set the UIImageView's image to background.png. Use [UIColor clearColor] as the table's background.
You need to put a UIImageView beneath your table view, set the table view's background color to clear (or in IB, set the opacity property of its background at 0). Then construct your CELL views to have clear areas that your background image can be seen through. You can do that programmatically or in IB (it's easier to visualize in IB, but the code to hook it all together is a bit tricky).