My subview is not responding click event - iphone

I am creating a app that display subview like ActionSheetView and in that i have added UIGridView and UIPageControll thru outlet , but now when i click the cell it does not respond ,my subview is a ViewController with the nib file.
and if i create a button and add in my popupview programmatically then it wil displaying, and also get the click event, but anything in outlet does not respond.
i have tried to set userinteraction enable in my subview but it does not done any good.
here is my code for first view that display subview by clicking barbutton:
- (void)popUpView:(id)sender {
//self.view.backgroundColor = [UIColor darkGrayColor];
bGView = [[UIView alloc] init]; /this is the background view and all view is added in it
bGView.frame = CGRectMake(0,0,320,490);
bGView.backgroundColor = [UIColor clearColor];
bGView.alpha = 0.8 ;
CGRect viewFrame = CGRectMake(10, 90, 300, 300);
aPopUpViewController = [[PopUpViewController alloc] initWithNibName:#"PopUpViewController" bundle:nil]; //this is my view controller and when this shows on screen it display my greed view
aPopUpViewController.view.frame = viewFrame;
aPopUpViewController.view.userInteractionEnabled = YES;
[bGView addSubview:aPopUpViewController.view];
button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self
action:#selector(aMethod:)
forControlEvents:UIControlEventTouchDown];
button.backgroundColor = [UIColor clearColor];
[button setBackgroundImage:[UIImage imageNamed:#"close_button.png"] forState:UIControlStateNormal];
button.frame = CGRectMake(-1, 80, 30, 30);
[bGView addSubview:button];
//for view animation
/*
// from bottom to center animation
[bGView setFrame:CGRectMake( 0.0f, 480.0f, 320.0f, 480.0f)]; //notice this is OFF screen!
[UIView beginAnimations:#"animateTableView" context:nil];
[UIView setAnimationDuration:0.4];
[bGView setFrame:CGRectMake( 0.0f, 0.0f, 320.0f, 480.0f)]; //notice this is ON screen!
[UIView commitAnimations];*/
//for page like effect
/*[UIView transitionWithView:self.view duration:0.5
options:UIViewAnimationOptionTransitionCurlUp //change to whatever animation you like
animations:^ { [self.view addSubview:bGView]; }
completion:nil];*/
/*CATransition *transition = [CATransition animation];
transition.duration = 1.0;
transition.type = kCATransitionReveal; //choose your animation
[bGView.layer addAnimation:transition forKey:nil];
[self.view addSubview:bGView];*/
aPopUpViewController.view.userInteractionEnabled = YES;
bGView.userInteractionEnabled = YES;
self.view.userInteractionEnabled = YES;
bGView.transform = CGAffineTransformMakeScale(0.01, 0.01);
[UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
bGView.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished){
// do something once the animation finishes, put it here
}];
[self.view addSubview:bGView];
addLabel.enabled = NO;
clipArt.enabled = NO;
emailItem.enabled = NO;
closeButton.enabled = NO;
self.navigationController.topViewController.title = #"Choose ClipArt";
ExampleAppDataObject* theDataObject = [self theAppDataObject];
theDataObject.navBarHide = #"no";
}
- (void)aMethod:(id)sender
{
//[aPopUpViewController.view removeFromSuperview];
//[button removeFromSuperview];
/*[UIView transitionWithView:self.view duration:0.5
options:UIViewAnimationOptionTransitionCrossDissolve//change to whatever animation you like
animations:^ { [bGView removeFromSuperview]; }
completion:nil];*/
[bGView removeFromSuperview];
addLabel.enabled = YES;
clipArt.enabled = YES;
emailItem.enabled = YES;
closeButton.enabled = YES;
self.navigationController.topViewController.title = #"Greeting's";
ExampleAppDataObject* theDataObject = [self theAppDataObject];
theDataObject.navBarHide = #"yes";
}
and this is how my screen look like
UPDATE
now i figured out my problem,problem is that i have given my whole view a tap listner,now i am adding grid view as subview so when ever i tap on cell rather then do select cell it will generate view tap gesture and thats why cell never selected,that's what i think..

add this line after you add every subviews in your main view..
[self.view bringSubviewToFront:yourGridView];

Related

Disable keyboard on UITextField on edit

Since when I click the UITextField the date picker is showing along with the keyboard, I want to hide the key board operation on dob-text field?Here my code
- (void)removeViews:(id)object
{
[[self.view viewWithTag:9] removeFromSuperview];
[[self.view viewWithTag:10] removeFromSuperview];
[[self.view viewWithTag:11] removeFromSuperview];
}
- (void)dismissDatePicker:(id)sender
{
CGRect toolbarTargetFrame = CGRectMake(0, self.view.bounds.size.height, 320, 44);
CGRect datePickerTargetFrame = CGRectMake(0, self.view.bounds.size.height+44, 320, 216);
[UIView beginAnimations:#"MoveOut" context:nil];
[self.view viewWithTag:9].alpha = 0;
[self.view viewWithTag:10].frame = datePickerTargetFrame;
[self.view viewWithTag:11].frame = toolbarTargetFrame;
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(removeViews:)];
[UIView commitAnimations];
}
- (IBAction)but
{
//[eventText resignFirstResponder];
[dob resignFirstResponder];
if ([self.view viewWithTag:9])
{
return;
}
CGRect toolbarTargetFrame = CGRectMake(0, self.view.bounds.size.height-216-44, 320, 44);
CGRect datePickerTargetFrame = CGRectMake(0, self.view.bounds.size.height-216, 320, 216);
UIView *darkView = [[UIView alloc] initWithFrame:self.view.bounds ];
darkView.alpha = 0;
darkView.backgroundColor = [UIColor blackColor];
darkView.tag = 9;
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(dismissDatePicker:)] ;
[darkView addGestureRecognizer:tapGesture];
[self.view addSubview:darkView];
datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height+44, 320, 216)] ;
datePicker.datePickerMode=UIDatePickerModeDate;
datePicker.tag = 10;
[datePicker addTarget:self action:#selector(changeDate:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:datePicker];
UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height, 320, 44)] ;
toolBar.tag = 11;
toolBar.barStyle = UIBarStyleBlackTranslucent;
UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] ;
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(dismissDatePicker:)] ;
[toolBar setItems:[NSArray arrayWithObjects:spacer, doneButton, nil]];
[self.view addSubview:toolBar];
[UIView beginAnimations:#"MoveIn" context:nil];
toolBar.frame = toolbarTargetFrame;
datePicker.frame = datePickerTargetFrame;
darkView.alpha = 0.5;
[UIView commitAnimations];
//[datePicker addTarget:self action:#selector(dateText:)forControlEvents:UIControlEventValueChanged];
//NSDateFormatter *_dateFormatter = [[NSDateFormatter alloc] init];
//_dateFormatter.dateStyle = NSDateFormatterFullStyle;
//dateText.text = [NSString stringWithFormat:#"%#",
// [_dateFormatter stringFromDate:datePicker.date]];
//[self.tableview reloadData];
}
I added the resignfirstresponder also,since its showing the same error
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
return [textField resignFirstResponder];
return [txt1 resignFirstResponder];//dob textfield
}
Use UITextField's delegate method
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if(textField == dob-text )
//load picker here
return NO; //hide keyboard
else
return YES; //show keyboard
}
A better solution is to set the UIPickerView as the inputView for the UITextField.
And you can set the UIToolBar as the inputAccessoryView of the inputView.
This way iOS will handle the displaying of all UIPickView.
Just set the properties top the correct views:
self.dateTextField.inputView = self.datePicker;
self.dateTextField.inputAccessoryView = self.inputToolbar;
On another note, getting views with viewWithTag: methods means that the you are looping thru all the views. Why not create properties for these views. It will be less messy and might be faster.
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
datePicker.hidden = NO;
[textField resignFirstResponder];
}
try in textFieldDidBeginEditing
-(void) textFieldDidBeginEditing:(UITextField *)textField{
[textField resignFirstResponder];
}
First of all a textfield should not have a popover - neither picker nor popover nor anything
Best solution would be to put a button - type custom - set image like a date selector image and add selector - in that case you would n't have any issues w.r.t textfields popover and the look would be good as well and you can customize it as per your requirement.

Animation in Uiscrollview with a button

I have tried the iCarousel, and add it to my project. I was able to put images. Now I'm trying to implement a method, that when the button was clicked the carousel will rotate.
I've tried this code:
- (IBAction) spinButton:(id)sender
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationDelegate:self];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:carousel
cache:YES];
[spinButton removeFromSuperview];
[UIView commitAnimations];
}
But it seems to be that only the carousel view is animating.
Following two method to changes aries may be your problem being solve by this,
-(void)TappedButton:(UIButton *)sender{
UIView *view=[carousel itemViewAtIndex:sender.tag];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationDelegate:self];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:view cache:YES];
// [spinButton removeFromSuperview];
[UIView commitAnimations];
NSLog(#"%d",sender.tag);
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
UILabel *label = nil;
//create new view if no view is available for recycling
if (view == nil)
{
view = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"page.png"]] autorelease];
// label = [[[UILabel alloc] initWithFrame:view.bounds] autorelease];
// label.backgroundColor = [UIColor clearColor];
// label.textAlignment = UITextAlignmentCenter;
// label.font = [label.font fontWithSize:50];
//
// [view addSubview:label];
UIButton *buttonForDisplay = [[[UIButton alloc] initWithFrame: view.bounds] autorelease];
buttonForDisplay.backgroundColor=[UIColor clearColor];
[buttonForDisplay setTitle:[NSString stringWithFormat:#"%d",index] forState:UIControlStateNormal];
buttonForDisplay.titleLabel.font = [label.font fontWithSize:50];
[buttonForDisplay addTarget:self action:#selector(TappedButton:) forControlEvents:UIControlEventTouchUpInside];
[buttonForDisplay bringSubviewToFront:view];
buttonForDisplay.tag = index;
/// view.tag=index;
[view addSubview:buttonForDisplay];
}
else
{
label = [[view subviews] lastObject];
}
//set label
// label.text = [[items objectAtIndex:index] stringValue];
return view;
}
EDIT
This method thru you can catch the reference of the carousel view.
- (UIView *)itemViewAtIndex:(NSInteger)index
Edit with Animation
UIViewController *nextViewController = [[UIViewController alloc] autorelease];
nextViewController.view.backgroundColor = [UIColor redColor];
CATransition *animation = [CATransition animation];
animation.duration = 3.5;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.type = kCATransitionPush;
animation.subtype = kCATransitionFromTop;
[self.navigationController pushViewController:nextViewController animated:NO];
[self.navigationController.view.layer addAnimation:animation forKey:nil];

Keyboard blocking my view

I have a UIView with another UIView inside it. On the inside UIView there is a textbox which I want to fill in. When I try to fill it in the keyboard blocks my view:
The UIViewController has the following
containerView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.view=containerView;
//The apropriate releases etc are further on...
When I touch it, the keyboard comes up as expected, but blocks the textbox I'm trying to fill in. How can I force the view to slide up?
The front view
OptionsFront * fv = [[OptionsFront alloc] initWithFrame:[UIScreen mainScreen].bounds];
[containerView addSubview:frontView];
In the front view is a subview
CGRect bounds = CGRectMake(0.0f, 210.0f, 280.0f, 130.0f);
sv = [[UIView alloc] initWithFrame:bounds];
[self addSubview:sv]; //added to frontView
In sv is a textbox near the botton:
rect = CGRectMake(70.0f, 20.0f, 100.0f, 27.0f);
cf = [self createTextField_Rounded:rect holder:#"+ve"];
[sv addSubview:cf];
So cf happens to be near the bottom of the page. I expected that when I select it, the whole display would move up, but the keyboard just moves up and blocks it.
What can I do?
Appendix:
- (UITextField *)createTextField_Rounded:(CGRect) frame holder:(NSString *) ph
{
UITextField *returnTextField = [[UITextField alloc] initWithFrame:frame];
returnTextField.borderStyle = UITextBorderStyleRoundedRect;
returnTextField.textColor = [UIColor blackColor];
returnTextField.font = [UIFont systemFontOfSize:17.0];
returnTextField.delegate = self;
returnTextField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
returnTextField.returnKeyType = UIReturnKeyDone;
returnTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
return returnTextField;
}
you need to move the textField up. in your UITextField delegate implement something like (from memory):
- (void)textFieldDidBeginEditing:(UITextField *)textField {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
textField.superview.frame = CGRectMake(0.0f, 100.0f, 280.0f, 130.0f); // experiment with frame size
[UIView commitAnimations];
}
and you'll want to move it back in textFieldDidEndEditing:

How to flip a UIButton horizontal with another UIButton on the backside?

I want a button that has a another button on the backside. When you press the button it should flip horizontal and show the other button. Apple did this in the ipod-App. When you hear a song you can press the button on the right site of the navigationbar and then the view flips and you can see all the songs from the album. But the interest point is that the button on the right side flips with the view horizontal.
How can I do this?
alt text http://img51.imageshack.us/img51/585/welyrics2jpg.png
Thanks for the answer!
I dont understand this atm.
My iPhone coach did it for me a while back.. but i wasnt looking at what he did.
So heres the code.
.h
#import <UIKit/UIKit.h>
#interface flipTesViewController : UIViewController {
IBOutlet UIView *containerView;
UIImageView *heads;
UIImageView *tails;
}
-(IBAction)test;
#end
.m
#import "flipTesViewController.h"
#implementation flipTesViewController
-(IBAction)test{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:containerView cache:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(test)];
[UIView setAnimationDuration:.5];
if(heads.tag==1){
[containerView addSubview:heads];
heads.tag=2;
}
else{
[containerView addSubview:tails];
heads.tag=1;
}
[UIView commitAnimations];
}
- (void)viewDidLoad {
[super viewDidLoad];
heads = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"NZHeads.png"]];
tails = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"NZTails.png"]];
[containerView addSubview:heads];
}
//other method built in to view based template
#end
On 3.x there's a simpler way:
Make the "backside view" as a UIViewController or one of its subclasses.
When the your "flip" button is pressed, call
.
backsideViewCtrler.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:backsideViewCtrler animated:YES];
-(void)viewDidLoad
{
UIButton *btn; = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(x, y, 60, 40);
btn.backgroundColor = [UIColor clearColor];
[btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
btn.tag=count;
[buttonWithTag setBackgroundImage:[UIImage imageNamed:#"2.png"] forState:UIControlStateNormal];
[btn setTitle:[NSString stringWithFormat:#"%d",btn.tag] forState:UIControlStateNormal];
[view_frame addSubview:btn];
[btn addTarget:self action:#selector(Click:)forControlEvents:UIControlEventTouchUpInside];
}
//action
- (IBAction)Click:(id)sender
{
UIButton *click_btn = (UIButton *)sender;
NSLog(#"%d",click_btn.tag);
UIButton *buttonWithTag = (UIButton *)[view_frame viewWithTag:click_btn.tag];
CATransition *animation = [CATransition animation];
animation.delegate = self;
animation.duration = 1.0;
animation.timingFunction = UIViewAnimationCurveEaseInOut;
animation.fillMode = kCAFillModeForwards;
animation.removedOnCompletion = NO;
animation.type = #"oglFlip";
[buttonWithTag.layer addAnimation:animation forKey:nil];
[buttonWithTag setBackgroundImage:[UIImage imageNamed:#"1.png"] forState:UIControlStateNormal];
}

iphone: rotating flipped view when rotating visible view

I have a resizing issue when rotating a view controller that has two views which I switch between using the flip animation.
The problem appears if i do the following steps:
Rotate the device when viewing the tableview.
Click the info button.
Rotate the device (infoView appears stretched).
Click on info button (tableview appears stretched)
It appears that the view that is not added to the superview is not resizing correctly, since it was not part of the composite views when the device was rotated.. Is there any way to get this view auto resized correctly?
Below is a code sample
- (void)viewDidLoad {
[super viewDidLoad];
//background image
backgroundImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"bg-app.png"]];
backgroundImageView.autoresizingMask = (UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight);
[self.view addSubview: backgroundImageView];
[backgroundImageView release];
//infoView
aboutImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"About.png"]];
aboutImageView.autoresizingMask = (UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight);
//tableView
self.tableView = [[[UITableView alloc ] initWithFrame:[[UIScreen mainScreen] bounds] style:UITableViewStylePlain] autorelease ];
//set the rowHeight once for performance reasons.
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.rowHeight = 75;
self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.autoresizingMask = (UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight);
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.autoresizesSubviews = YES;
//set the rowHeight once for performance reasons.
[self.view addSubview: tableView];
//[tableView release];
[self.view setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth];//for resizing on rotation
//info button
UIButton * infoDarkButtonType = [[UIButton buttonWithType:UIButtonTypeInfoLight] retain];
infoDarkButtonType.frame = CGRectMake(0.0, 0.0, 25.0, 25.0);
infoDarkButtonType.backgroundColor = [UIColor clearColor];
[infoDarkButtonType addTarget:self action:#selector(infoAction:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *buttonInfo = [[UIBarButtonItem alloc] initWithCustomView:infoDarkButtonType];
self.navigationItem.rightBarButtonItem = buttonInfo;
[infoDarkButtonType release];
self.navigationItem.rightBarButtonItem = buttonInfo;
[buttonInfo release];
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return YES;
}
- (void)infoAction:(id)sender{
NSLog(#"Clicked on the info button");
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75]; /* Sub. duration here */
UIView *superview;
if ((superview = [tableView superview])) {
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:superview cache:YES];
[tableView removeFromSuperview];
[superview addSubview:aboutImageView];
} else if ((superview = [aboutImageView superview])) {
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:superview cache:YES];
[aboutImageView removeFromSuperview];
[superview addSubview:tableView];
}
[UIView commitAnimations];
}
Thanks
Try putting the code in viewWillAppear:animated. It's called every time your view will appear. View did load is called once.