Inside my viewDidLoad, I have the following:
UILongPressGestureRecognizer *longpressGesture =[[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(handleLongpressGesture:)];
longpressGesture.minimumPressDuration = 1;
longpressGesture.allowableMovement = 5;
longpressGesture.numberOfTouchesRequired = 1;
[self.tableView addGestureRecognizer:longpressGesture];
[longpressGesture release];
I created the following:
-(IBAction) handleLongpressGesture:(UIGestureRecognizer *) sender {
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"Delete Record?" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:#"Yes",#"No",nil];
[actionSheet showInView:self.view];
[actionSheet release];
}
Using the simulator, when I long press, two action sheet shows up instead of the one.
Any ideas as to why this is so?
Is it a problem with the simulator?
It's not a problem with the simulator.
The gesture handler is called multiple times as the gesture goes through different states (began, ended, etc).
You need to check the gesture's state in the handler method:
-(IBAction) handleLongpressGesture:(UIGestureRecognizer *) sender {
if (sender.state == UIGestureRecognizerStateBegan)
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] init...
[actionSheet showInView:self.view];
[actionSheet release];
}
}
Related
I want to dismiss UIActionsheet when user taps anywhere else on screen. I don't want to
provide cancel button.
My code
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:sheetTitle delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles: nil];
[sheet setTag:indexPath.row];
for (NSString *buttonTitle in buttonTitles)
{
[sheet addButtonWithTitle:buttonTitle];
}
[sheet showFromToolbar:self.navigationController.toolbar];
[sheet release];
[buttonTitles release];
Make your ActionSheet object global and then allocate it into your block. then you can dismiss it from outside touches event on your view.
add following block into your view.
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[sheet removeFromSuperView];
sheet=nil;
}
hope this will help you
try this
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapOut:)];
tap.cancelsTouchesInView = NO;
[actionSheet.window addGestureRecognizer:tap];
[tap release];`<br> `-(void)tapOut:(UIGestureRecognizer *)gestureRecognizer {
CGPoint p = [gestureRecognizer locationInView:self.actionSheet];
if (p.y < 0) {
[actionSheet dismissWithClickedButtonIndex:0 animated:YES];
}
}
It is UIActionsheet default feature to dismiss when touch outside. No Need of additional code.
[sheet showFromToolbar:self.navigationController.toolbar];
is making the problem I think. Change it to
[sheet showInView:[UIApplication sharedApplication].keyWindow];
Declare ActionSheet globally and then paste this code after the viewdidload
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[super touchesBegan:touches withEvent:event];
[actionSheet dismissWithClickedButtonIndex:0 animated:YES];
}
works 100%
My UIActionSheet is transparent when it displays. How do I change this? here's a screenshot of what the problem looks like:
the code:
- (IBAction)btnTakePicture_Clicked:(id)sender
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"Select Image from..." delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Camera", #"Image Gallary", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
actionSheet.alpha=0.90;
actionSheet.tag = 1;
[actionSheet showInView:self.view];
UIButton *btn = (UIButton *)sender;
intButton = btn.tag;
}
I believe what's causing problems is
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
Probably in iOS 7 this causes the transparency. Try removing it.
Also you are setting the alpha to 0.9, which will cause some transparency in any case (not as showed in the screenshot though). If you want a completely opaque action sheet, remove also
actionSheet.alpha=0.90;
Removing the lines:
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
actionSheet.alpha=0.90;
Should do the trick
So for some reason after I've just added an actionsheet it's coming up and stopping above the bottom of the screen. Is there a way to manually tell this where to stop?
- (void)showActionSheet:(UIButton *)standardButton{
UIActionSheet *popupQuery = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:#"Cancel Button" destructiveButtonTitle:nil otherButtonTitles:#"Choose From Library", #"Take Photo", nil];
popupQuery.actionSheetStyle = UIActionSheetStyleAutomatic;
[popupQuery showInView:self];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
// Choose from library tapped
NSLog(#"Choose");
} else if (buttonIndex == 1) {
// Take a photo tapped
NSLog(#"Take");
}
}
Try self.view instead of self.
I am creating an Alert view on click of a button. I have placed a UITextfield in it. But the Alertview is shifted upwards in the screen. I am not able to bring it back at the center of the screen.
Here is my code and Screenshot.
and the code for creating this Alert view is this:-
- (IBAction)btn_cancelAppointment_click:(id)sender
{
// Here We are Creating Alertview which asks for
UIAlertView* cancelAlert = [[UIAlertView alloc] init];
[cancelAlert setDelegate:self];
[cancelAlert setTitle:#"Are you sure you want to request cancellation of this appointment?"];
[cancelAlert setMessage:#" "];
[cancelAlert addButtonWithTitle:#"NO"];
[cancelAlert addButtonWithTitle:#"YES"];
UITextField * txt_cancelNote = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 88.0, 245.0, 30.0)];
[txt_cancelNote setBackgroundColor:[UIColor whiteColor]];
[txt_cancelNote setBorderStyle:UITextBorderStyleRoundedRect];
[txt_cancelNote setPlaceholder:#"Enter cancellation note"];
txt_cancelNote.tag = 11;
[cancelAlert addSubview:txt_cancelNote];
cancelAlert.delegate = self;
[cancelAlert show];
}
So, if somebody can tell me how to bring it back to the center of the screen. Any help will be highly appreciated.
Give a try by setting the transform property of the UIAlertView
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:#"Test" message:nil delegate:self cancelButtonTitle:#"OK" otherButtonTitles: nil];
alertView.transform = CGAffineTransformMakeTranslation(x, y);
I am new to xcode and first time at stackoverflow. I have a pickerview as subview of UIActionSheet. Pickerview is used to select $ amount for a field.
On iOS >=4.2, pickerview shows on top of actionsheet as expected. However, with ios 4.0/1, the actionsheet covers pickerview, though i can select the values.
The code
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
UIActionSheet *sheet = [[UIActionSheet alloc]initWithTitle:#"Select Bill Amount Before Tips" delegate:self cancelButtonTitle:nil destructiveButtonTitle:#"Done" otherButtonTitles:nil];
[sheet addSubview:pickerview];
pickerview.showsSelectionIndicator = YES;
[sheet showInView:self.tabBarController.view];
/******** action sheet size **********/
CGRect menuRect = sheet.frame;
CGFloat orgHeight = menuRect.size.height;
menuRect.origin.y -= 216;
menuRect.size.height = orgHeight+216;
sheet.frame = menuRect;
/**************************************/
CGRect pickerRect = pickerview.frame;
pickerRect.origin.y = orgHeight;
pickerview.frame = pickerRect;
// [self.tabBarController.view bringSubviewToFront:pickerview];
[sheet release];
return NO;
}
thanks for helping out.