How to create an iPhone Album's “email photo, MMS, Assign To Contact..” like sliding view?

StackOverflow https://stackoverflow.com/questions/2486362

문제

I learned how to create a view controller and make the view slide in from bottom. But the one in iphone album looks different. It darkens the rest of the visible portion of the screen when the view slides in. How do I create a similar one? I want to add buttons like "save, cancel, email" etc into the sliding view.

도움이 되었습니까?

해결책

This actually isn't a typical "sliding" (or modal) view, but a UIActionSheet. Basically, the idea is that you initialize the view (usually in your view controller) with

UIActionSheet *sheet = 
    [[[UIActionSheet alloc] initWithTitle:@"My sheet"
                                 delegate:self
                        cancelButtonTitle:@"Cancel"
                   destructiveButtonTitle:nil
                        otherButtonTitles:@"Email", @"MMS", nil] autorelease];

Then present it using

[sheet showInView:[self view]];

Once it's onscreen, the delegate (self, or your view controller, in this example) will receive the UIActionSheetDelegate message actionSheet:clickedButtonAtIndex: (as well as some others; see the documentation for more), so you'll want to add <UIActionSheetDelegate> to your interface declaration for the delegate and implement that method, like

- (void)actionSheet:(UIActionSheet *)actionSheet 
    clickedButtonAtIndex:(NSInteger)buttonIndex {
    switch(buttonIndex) {
        // Do things based on which button was pushed
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top