UIColor groupTableViewBackgroundColor is transparent - cocoa-touch

I have a grouped style UITableView on my navigation stack, and when I click on a cell, I push a UIDatePicker onto the stack. The problem is that I want this custom view to have the same background color as my table view.
I tried setting the background color of my custom view like:
datePicker.backgroundColor = [UIColor groupTableViewBackgroundColor];
But this comes out transparent. I also tried modifying the underlying CGColor object to have an alpha of 1.0, which caused the background color to be black.
The following does work as expected:
datePicker.backgroundColor = [UIColor lightGrayColor];
But, of course, this color doesn't quite match the grouped table background color.
Am I going about this all wrong? I found a similar post about this here, but no helpful response.

What do you mean you "push a UIDatePicker onto the stack"? Why dont you try animating the UIDatePicker into view?
when the view loads, create the picker and set the frame off screen, such as
[picker setFrame:CGRectMake(0,960,320,216)];
then instead of "pushing" the picker, animate it into view like:
[UIView beginAnimations:nil context:NULL];
[picker setFrame:CGRectMake(0,200,320,216)];
[UIView commitAnimations];
And when you want to dismiss the picker, just hide it like:
[UIView beginAnimations:nil context:NULL];
[picker setFrame:CGRectMake(0,960,320,216)];
[UIView commitAnimations];
If you need to, you can also add a toolbar with a "done" button to dismiss the picker, works great for me.
If the contents of the picker are going to be displayed on the table, then you can set the frame of the table in that animation sequence. in the first one, make the table half the size (like 150 for my example would work perfect), then in the hide sequence, make the table the original size (415 for this example). And when you hide the picker, call [tableView reloadData]; to refresh the table.

Related

Change background colour BEHIND ViewController frame (when frame.origin is altered)?

I have an app which intakes client details, built for iPad. When the user taps a UITextField towards the bottom half of the ViewController, the frame programatically shifts upwards so that the fields aren't hidden behind the keyboard. (I tried to implement a UIScrollView but just cannot seem to get it working.) The slight issue I'm having now is when the frame shifts up, you can vaguely see the black behind it. This isn't a huge issue because I have changed the animation time and the black background is barely visible, but I have a feeling there is a more elegant solution.
Here is my code to shift the frame:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
// Animate frame up if lower textfields are tapped
if (([textField isEqual:_emailField]) || ([textField isEqual:_dobField]) || ([textField isEqual:_niNumField])) {
[UIView beginAnimations:nil
context:NULL];
[UIView setAnimationDuration:0.35f];
CGRect frame = self.view.frame;
frame.origin.y = -210;
[self.view setFrame:frame];
[UIView commitAnimations];
} else {
// Return frame to original position if other textfields are tapped
[self dismissKeyboard];
}
return YES;
}
- (void)dismissKeyboard {
[UIView beginAnimations:nil
context:NULL];
[UIView setAnimationDuration:0.15f];
CGRect frame = self.view.frame;
frame.origin.y = 0;
[self.view setFrame:frame];
[UIView commitAnimations];
}
Here is a brief screenshot of what I'm trying to describe. Left picture is the ViewController normally, right picture is when the frame has been shifted upwards. You can see (vaguely) almost in line with the second row of characters is where the frame stops.
I realise this doesn't seem like an issue because it is barely visible at all, but I have had to speed up the animation hiding the keyboard or else the frame drags behind and the black background becomes visible. I am wondering: is there a way to change this colour? Or is that something we don't have access to? If anyone can suggest a more elegant method for what I am trying to do, I'd gladly take a better solution. Thanks in advance.
Your UIViewController's view is added to the main UIWindow. So you should be able to achieve what you want by changing the UIWindow's background color.
In the UIApplicationDelegate:
self.window.backgroundColor = [UIColor whiteColor];
However, what you're doing isn't the best way to solve the problem of the keyboard covering up the text fields. You should use a UIScrollView or a UITableView to manage this view and use content insets to shift the view up or down.

Event to hide UIDatePicker

I've got UIDatePicker on UIViewController.
After user selected the date and clicked outside the UIDatePicker I would like hide UIDatePicker like:
-(void)hidePicker
{
[UIView beginAnimations:#"SlideOutPicker" context:nil];
[UIView setAnimationDuration:0.5];
[_datePicker setCenter: CGPointApplyAffineTransform(_datePicker.center, _datePicker.transform)];
[_datePicker setTransform:CGAffineTransformMakeTranslation(0, 0)];
[UIView commitAnimations];
}
I try
[_datePicker addTarget:self action:#selector(hidePicker) forControlEvents:UIControlEventTouchUpOutside];
but event doesn't happen, can you get me some advise?
I don't wanna use UIControlEventValueChanged because DatePicker should not hide each time when user change the date
You cannot use UIControlEventTouchUpOutside for this behavior. In your case you need to create a transparent view or button outside the picker and set action for that to dismiss the picker. Set the background color of this view/button as clear color to achieve this. On tap of the button or view, you might have to dismiss the picker.
UIControlEventTouchUpOutside is mainly used for touching inside the view and moving out the finger. While moving out of the bounds of the view, it triggers the event.
Just check if the touch is not inside the bounds of the UIDatePicker each time you touch the screen.Have you tried to set hidden=YES; ? I guess you can change its visibility inside the animation block. BTW, if you're developing for iOS 4+ then you'd better use new (they're actually not new any more) UIView class methods methods for animations because using beginAnimations and commitAnimations blocks is discouraged by Apple. Below are those methods I mentioned:
animateWithDuration:animations:
animateWithDuration:animations:completion:
animateWithDuration:delay:options:animations:completion:
More information in http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/UIView/UIView.html#//apple_ref/doc/uid/TP40006816-CH3-SW111

UIView clipToBounds is not stopping a subView receiving touches outside the parent view

I have two UIViews. I'm using one to contain the other so that I can slide one inside the other. I'm encountering an issue where even though a subView is clipped to the bounds of its parent, it is still receiving touch events and blocking access to other underlying views.
I have three screenshots that show the layout. I've coloured the parent green and the child red.
The idea is that the user clicks "View" and the subView slides up. When the subView is in the default position, the UITabBar is covered and cannot be clicked. You can see this in the first image where the red view is present at the bottom. When the subView is moved to the top, the UITabBar can be clicked as it's now visible. In the third image, I've show what it's like with clipToBounds enabled on the green UIView.
I've enabled clipToBounds, so I cannot understand why the subView is blocking the underlying UITabBar. Is my understanding of clipToBounds completely wrong??
Using clipToBounds only affects the visual layout of a subView, not the logical layout. This means that whilst my subView isn't visible to the eye, it's visible to touch.
I've worked around this issue by animating the size of the subView rather than its position. In my code below, the stationProximityView is the subView. I animate its size by 40 pixels to bring the black title back into view.
[UIView beginAnimations:#"stationProximityBar" context:NULL];
self.stationProximityView.view.frame = CGRectOffset(self.stationProximityView.view.frame, 0, -40);
[UIView commitAnimations];
When I no longer need it, I animate it out of view.
[UIView beginAnimations:#"stationProximityBar" context:NULL];
self.stationProximityView.view.frame = CGRectMake(0 ,0, 320, 500);
[UIView commitAnimations];
If the user taps the view button, the entire subView is shown:
[UIView beginAnimations:#"stationProximityBar" context:NULL];
self.stationProximityView.view.frame = CGRectMake(0,460,320,40);
[UIView commitAnimations];
Dismissal causes the view to be hidden in the same way as the small bar.
[UIView beginAnimations:#"hideStationProximityBar" context:NULL];
self.stationProximityView.view.frame = CGRectMake(0,0,320,500);
[UIView commitAnimations];
At the moment, this code is only being tested on the iPhone 5, so the hard-coded height of 500 would causes issues on previous iPhone models.

Resize UIView from point with animation

I have UIButton on view, when I taped on this button I want to create new view and display it on iPad screen, how I can view this view like growing from button to full screen ?
Next time actually show some effort with what you have tried etc when asking for help
- (void)buttonTapped:(UIButton *)button;
{
UIView *expandingView = [[UIView alloc] initWithFrame:button.frame];
expandingView.backgroundColor = [UIColor redColor];
[self.view addSubview:expandingView];
[UIView animateWithDuration:.25f
animations:^{
expandingView.frame = self.view.bounds;
}];
}
On the button click event.
Create the view with frame with size zero and orgin as center of
button
2.add to mainview
3.Then using animation block change
the frame to orginal
What are block-based animation methods in iPhone OS 4.0?
use this qn to find how to add animation

How to implement the effect of popping up tableview from bottom of screen?

I'm a newbie of Xcode and Objective-c. Recently I wanna do a task about popping up tableviews. When a button is pressed, the tableview should pop up from the bottom of the screen. The tableview will contain just a few items so I don't wanna it occupy full screen. I read the manual and found UIModalPresentationStyle, but it seems not fulfill my requirements. So what's the more accurate methods I can use?
While #Bharat J's answer is correct, those methods are deprecated in iOS 4.0.
The latest and greatest implementation is + (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations
Implemented as:
[UIView animateWithDuration:0.5 animations: ^{
tableView.frame = newFrame;
}
];
You can use below code to create an animation block . Set the frame for the table view as (0,480,320,0) When you hit a button change the frame of the table view in the animation block and make it to CGRectMake(0,200,320,280) or something .
[UIView beginAnimations:#"AnimateTableView" context:view];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
tableView.frame = CGRectMake(0, 200 , 320, 280);
[UIView commitAnimations];
The same animation block for hiding it again but with the frame again begin set to CGRectMake(0,480,320,0). This should work in your case .
Another option would be to use a UIActionSheet and add the uitableview as a subview.
Here is a very similar question about how to add a UIPickerview with similar effect.
Add UIPickerView & a Button in Action sheet - How?