In Apple's stock 'Messages' app, tapping the camera button reveals popup buttons allowing the user to take a photo/video or choose an existing one. How would I implemented this same button design? Is the procedure the same for both iPhone & iPad?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
It's called a UIActionSheet
. You use it like this
UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:@"Foo" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"foo1", @"foo2", nil];
[action showInView:self.view];
(change the foos to whatever). To detect what button was clicked, implement the UIActionSheetDelegate
's actionSheet:clickedButtonAtIndex:
delegate method. For example:
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
NSString *title = [actionSheet buttonTitleAtIndex:buttonIndex];
if ([title isEqualToString:@"foo1"]) {
// do stuff...
}
}
And yes, this works on both the iPhone and iPad (as @bobnoble pointed out, the iPad version uses a popover view, not an action sheet, but action sheets work on both).