I have a storyboard in which i am pushing one view on top of another view in the navigation controller.(Simple push Segue). I am setting the background of the new view in the viewDidLoad method and using the following code to do so.
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"welcome_bg_pattern"] ];
But during the push animation form one view to the other view i can see both the views overlapping. Can some body can guide me how i can set the background so that i don't have that problem.
Here are the attach imaged
first View
During push Transition. here you can see both the vies are overlapped this will not happen if i just simple set a redColor as background color of the view
Second View
I have also tried by setting the background image in the viewWillAppear
Any help will be great
Instead of set background image of self.view like
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"welcome_bg_pattern"] ];
set background image in UIImageView with set proper frame and add UIImageView as subView of self.view.
Related
I'm loading a view controller modally via another view controller and I'm trying to change the background color using:
override func viewDidLoad() {
super.viewDidLoad()
transparentBG.backgroundColor? = UIColor.black.withAlphaComponent(0.4)
// transparentBG is a UIView defined in storyboard
}
While the view is animating into position (sliding up) it maintains the alpha value I set. But once it reaches the top of the screen it removes the alpha component and is changing the color to what looks like the color with the alpha component, so like a gray color, but with no transparency as seen in the image below.
Is there anyway to maintain the alpha component after if finishes loading?
Step one: Change this to an overFullScreen presentation.
Step two: There is no step two.
just set presentaion style on viewContriller
[myViewcontroller setModalPresentationStyle:UIModalPresentationCustom];
[myViewcontroller setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self.navigationController presentViewController:myViewcontroller animated:true completion:nil];
What is happening is that the alpha is being kept, but the previous view is being removed once the animation is complete.
There are a couple approaches you can take.
Take a screen shot of the previous view and insert that as a background in the new view. Look at the drawViewHierarchyInRect function. You can grab the screen shot in the new view controller's init method, then set it as a background image in the viewDidLoad.
The other approach would be to add the overlay as a subview, either to the existing view, or even the window itself.
I've used both methods successfully.
I'm pushing a UIViewController (A) with clearColor as background in a UINavigationController (N).
N is placed inside a Container View. This view has a background that I want to show always.
Then, when Push is animated it shows a grey/transparent background in my VC (A) and when it finishes its animation, it shows correctly.
Is there any way to avoid this grey color?
I have 'done' it by putting a white view background in A and making it disappear in viewDidAppear but I think it can be done without that trick...
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
__weak TestsViewController *weakSelf = self;
[UIView animateWithDuration:.3 animations:^{
TestsViewController *ownSelf = weakSelf;
ownSelf.backgroundView.alpha = 0;
}];
}
Set your app's window's background colour to white:
// applicationDidFinishLaunching
self.window.backgroundColor = [UIColor whiteColor];
The push animation often ends up using the background colour of the window behind the transparent areas, and the window background colour is clear by default, so it shows black through the transparent navigation bars and toolbars.
EDIT: Sorry, misunderstood what the issue was. When you push a view controller with a transparent background colour, the background you see behind the view controller is the shadow that is rendered behind your view controller (you can see the edge of it when in a non-transparent view controller).
This question has an answer to your issue. Basically, you have to implement a custom animation controller, to provide the transition animation yourself (as described here). It would probably be easier to continue using your trick than implementing your own custom navigation transition.
I am pushing a view controller via:
[self.navigationController pushViewController:[[UIViewController alloc] init] animated:YES];
But the animation lags/pauses a for half a second mid way through. The animation is not complete. Here's the gif;
With out more detail I can think of 2 possible problem with that.
Is there Shadow added in code to the view that will be covered by the new ViewController. If it is the case, use ShadowPath or an translucent view instead (the property Shadow is expensive while animating, been there done that)
Is the backgroundColor of new ViewController "clearColor" ? I've seen strange rendering problem with that kind of thing.
Try:
UIViewController *vc = [[UIViewController alloc] init];
vc.view.backgroundColor = [UIColor whiteColor];
[self.navigationController pushViewController:vc animated:YES];
That is the 2 possible problems I can think of the top of my head with so few detail.
Never rely on the default background color, it has change with iOS version and is not consistant across controls and can even be different if the view is created in code or from a Xib (in the same iOS version).
In app delegate, set your window's background color to white.
window?.backgroundColor = .white
Also in the the pushed view controller, set its view to white.
view.backgroundColor = .white
I experienced the same issue when programmatically embedding my view controller in a UINavigationController.
While setting the background color as suggested by VinceBurn solved the pausing, it made the entire animation white, fading in the actual content only when the animation finished.
For me the problem was solved by making sure the content was correctly sized in -viewDidLoad.
I've subclassed UINavigationBar in order to set a custom background image.
I'm using it to initialize a UINavigationController with:
-(id)initWithNavigationBarClass:(Class)navigationBarClass toolbarClass:(Class)toolbarClass
The problem is that when new UIViewControllers get pushed on to the NavigationController stack, the title text animates in from the right across the background image in a way that looks a bit sucky.
Problem: How to tweak the animation so e.g. it fades in as it animates across.
The closest I've come is by creating a custom fade-up animation in the pushed/popped ViewController class. I use a NSTimer to trigger changes to the alpha of the titleView:
UILabel *titleView = (UILabel *)self.navigationItem.titleView;
...
-(void)setAlpha:(float)alpha
{
titleView.textColor = [UIColor colorWithRed:grayShade green:grayShade blue:grayShade alpha:alpha];
}
However, if I trigger this in 'ViewDidAppear' it's already too late and the fade-up starts after the new view has finished sliding in. I figured that I could trigger it in 'ViewWillAppear' but that this might lead to indeterminate and inconsistent timings on different devices. Am I right in this assumption and if so, how can I customize the animation in the way I want to?
I want to push a view controller onto the navigation stack but I don't want its view to initially appear - in other words I want the view that was visible when the view controller is push to still be visible.
I tried setting the view controller's view's alpha value to 0.0 which I thought would make it transparent. But instead what is happening is that when I push the view controller on the the stack the screen is white. If I set the alpha to 1.0 then the view controller's view appears as expected.
Why is it white and not transparent?
you will have to add the view to the viewcontrollers manually
Not pushing it
For example do the following
YourViewController *vc = [[YourViewController alloc] init];
[self.view addSubview:vc.view];
vc.view.alpha = 0.0;
//Animate Here
vc.view.alpha = 1.0;
//Commit Animate Here
Please not that you will have to do some additional coding to implement the release of the vc, since now you have retained vc.view you will not be able to release vc easily,
Another solution is instead of implementing the second view as a viewcontoller implement it as uiview, and the xib class will be view and not uiviewcontroller
Maybe make sure that the opaque property is set to NO?
Or perhaps the view you're pushing on was built in interface builder, and you have a background color of white with another view you put on top of it and you only changed the opacity of the subview?