Thursday, 12 September 2013

UIPickerView Animation Hide and Show Failed

UIPickerView Animation Hide and Show Failed

I have this on my interface file :
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
<UIPickerViewDataSource, UIPickerViewDataSource>
// PickerView Array
@property (strong, nonatomic) NSArray *pickerNames;
@property (strong, nonatomic) NSArray *pickerValues;
@property (strong, nonatomic) IBOutlet UIPickerView *picker;
- (IBAction)buttonSelectPicker;
@end
and I have this on my implementation file :
- (void)viewDidLoad
{
[super viewDidLoad];
// PickerView Array
_pickerNames = @[@"Data1", @"Data2", @"Data3", @"Data4", @"Data5"];
_pickerValues = @[@"val1", @"val2", @"val3", @"val4", @"val5"];
_picker.frame = CGRectMake(0, 1000, 320, 216);
}
all of those code works perfectly on my iPod (iOS 6.1.3) now, I have
problems with what actually I want to do more... they are...
when the app loaded for the first time, UIPickerView is hidden (outside
the screen area). I tried by adding this line (on viewDidLoad) but it
didn't work.
_picker.frame = CGRectMake(0, 1000, 320, 216);
then when user tap the buttonSelectPicker button, UIPickerView shows up.
this lines of code also didn't work :
- (IBAction)buttonSelectPicker { [UIView beginAnimations:nil
context:NULL]; [UIView setAnimationDuration:0.3];
_pickerviewContainer.frame = CGRectMake(0, 289, 320, 216); [UIView
commitAnimations]; }
and when user tap anywhere outside UIPickerView area, it will hide the
UIPickerView. I have this code to dismiss keyboard, but I don't know how
to modify to dismiss UIPickerView :
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { for
(UIView * txt in self.view.subviews){ if ([txt isKindOfClass:[UITextField
class]]) { [txt resignFirstResponder]; } } }
thank you...

No comments:

Post a Comment