核心代码如下,具体的请参考附件。
PopupPanelViewController.h
#import <UIKit/UIKit.h> @class VerticalPopupPanel; @interface PopupPanelViewController : UIViewController<UIImagePickerControllerDelegate,UINavigationControllerDelegate> { IBOutlet VerticalPopupPanel *verPanel; } - (IBAction)doPopupAction:(id)sender; - (IBAction)cameraBtnTouchDown:(id)sender; - (IBAction)settingBtnTouchDown:(id)sender; @property (nonatomic, retain) IBOutlet VerticalPopupPanel *verPanel; @end
PopupPanelViewController.m
#import "PopupPanelViewController.h" #import "VerticalPopupPanel.h" #import "SettingsViewController.h" @implementation PopupPanelViewController @synthesize verPanel; - (void)dealloc { [verPanel release]; [super dealloc]; } - (IBAction)doPopupAction:(id)sender { if (verPanel.isPopup) { [verPanel hide]; } else { [verPanel popup]; } } - (IBAction)cameraBtnTouchDown:(id)sender { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.delegate = self; picker.sourceType = UIImagePickerControllerSourceTypeCamera; [self presentModalViewController:picker animated:YES]; [picker release]; } - (IBAction)settingBtnTouchDown:(id)sender { SettingsViewController *settingView = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil]; [self.navigationController pushViewController:settingView animated:YES]; [settingView release]; } #pragma mark - #pragma mark UIImagePickerController delegate - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ [picker dismissModalViewControllerAnimated:YES]; } - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{ [picker dismissModalViewControllerAnimated:YES]; } @end
VerticalPopupPanel.h
#import <UIKit/UIKit.h> #import <QuartzCore/QuartzCore.h> @interface VerticalPopupPanel : UIView { CGRect popupRect; CGRect hideRect; float panelHeight; BOOL isPopup; } @property BOOL isPopup; - (void)popup; - (void)hide; @end
VerticalPopupPanel.m
#import "VerticalPopupPanel.h" @implementation VerticalPopupPanel @synthesize isPopup; - (id)initWithCoder:(NSCoder *)aDecoder { if (self = [super initWithCoder:aDecoder]) { popupRect = self.frame; hideRect = CGRectMake(popupRect.origin.x, popupRect.origin.y + popupRect.size.height, popupRect.size.width, 0); self.frame = hideRect; isPopup = NO; [self.layer setCornerRadius:10.0]; [self setClipsToBounds:YES]; } return self; } - (void)popup { isPopup = YES; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.2]; [UIView setAnimationCurve:UIViewAnimationCurveLinear]; [self setFrame:popupRect]; [UIView commitAnimations]; } - (void)hide { isPopup = NO; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.2]; [UIView setAnimationCurve:UIViewAnimationCurveLinear]; [self setFrame:hideRect]; [UIView commitAnimations]; } - (void)dealloc { [super dealloc]; } @end
示例图: