Add UIPickerView & a Button in Action sheet - How?

后端 未结 11 1429
遥遥无期
遥遥无期 2020-11-22 15:40

My application requires following things to be added in an action sheet.

  • UIToolbar
  • Button on UIToolbar
  • UIPicker Control

I have

11条回答
  •  隐瞒了意图╮
    2020-11-22 16:10

    Marcio's excellent solution to this question was of great help to me in adding subviews of any kind to a UIActionSheet.

    For reasons that are not (yet) entirely clear to me, the bounds of the UIActionSheet can only be set after it has been displayed; both sagar's and marcio's solutions successfully address this with a setBounds:CGRectMake(...) message being sent to the actionsheet after it is shown.

    However, setting the UIActionSheet bounds after the sheet has been displayed creates a jumpy transition when the ActionSheet appeaars, where it "pops" into view, and then only scrolls in over the final 40 pixels or so.

    When sizing a UIPickerView after adding subviews, I recommend wrapping the setBounds message sent to the actionSheet inside an animation block. This will make the entrance of the actionSheet appear smoother.

    UIActionSheet *actionSheet = [[[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
    
    
    // add one or more subviews to the UIActionSheet
    // this could be a UIPickerView, or UISegmentedControl buttons, or any other 
    // UIView.  Here, let's just assume it's already set up and is called 
    // (UIView *)mySubView
    [actionSheet addSubview:myView];
    
    // show the actionSheet
    [actionSheet showInView:[UIApplication mainWindow]];
    
    
    // Size the actionSheet with smooth animation
        [UIView beginAnimations:nil context:nil];
        [actionSheet setBounds:CGRectMake(0, 0, 320, 485)];
        [UIView commitAnimations]; 
    

提交回复
热议问题