Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

STPopup provides STPopupController, which works just like UINavigationController in popup style, for both iPhone and iPad. It's written in Objective-C and compatible with Swift.

License

NotificationsYou must be signed in to change notification settings

kevin-lyn/STPopup

Repository files navigation

STPopup providesSTPopupController, which works just likeUINavigationController in popup style, for both iPhone and iPad. It's written in Objective-C and compatible with Swift.

Features:

  • Push/Pop view controller into/out ofSTPopupController just likeUINavigationController.
  • Set navigation items throughself.navigationItem just like using aUINavigationController.
  • Support both "Form Sheet" and "Bottom Sheet" style.
  • Work well with storyboard(including segue).
  • Customize UI by usingUIAppearance.
  • Customizable popup transition style.
  • Auto-reposition of popup view when keyboard shows up, make sure yourUITextField/UITextView won't be covered by the keyboard.
  • Drag navigation bar to dismiss popup view.
  • Support both portrait and landscape orientation in iPhone and iPad.
  • iOS 7+.
  • Compatible with Swift.

Use Cases

Use Cases

Get Started

CocoaPods

pod'STPopup'

Carthage

github"kevin0571/STPopup"

Import header file
Objective-C

#import<STPopup/STPopup.h>

Swift

import STPopup

Initialize and present STPopupController
Objective-C

STPopupController *popupController = [[STPopupControlleralloc]initWithRootViewController:viewController];[popupControllerpresentInViewController:self];

Swift

letpopupController=STPopupController(rootViewController: viewController)popupController.present(in:self)

Set content size in view controller
Objective-C

@implementationViewController- (instancetype)init{if (self = [superinit]) {        self.title =@"View Controller";        self.navigationItem.rightBarButtonItem = [[UIBarButtonItemalloc]initWithTitle:@"Next"style:UIBarButtonItemStylePlaintarget:selfaction:@selector(nextBtnDidTap)];// It's required to set content size of popup.        self.contentSizeInPopup =CGSizeMake(300,400);        self.landscapeContentSizeInPopup =CGSizeMake(400,200);    }return self;}@end

Swift

classViewController:UIViewController{overrideinit(nibName nibNameOrNil:String?, bundle nibBundleOrNil:Bundle?){        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)        title="View Controller"        navigationItem.rightBarButtonItem=UIBarButtonItem(title:"Next", style:.plain, target:self, action: #selector(nextBtnDidTap))        // It's required to set content size of popup.        contentSizeInPopup=CGSize(width:300, height:400)        landscapeContentSizeInPopup=CGSize(width:400, height:200)}}

Set content size of view controller which is loaded from Storyboard
Set content size in storyboard or inawakeFromNib.
Storyboard

Push, pop and dismiss view controllers
Objective-C

[self.popupControllerpushViewController:[ViewControllernew]animated:YES];[self.popupControllerpopViewControllerAnimated:YES];// Popup will be dismissed if there is only one view controller in the popup view controller stack[self.popupControllerdismiss];

Swift

popupController?.push(viewController, animated:true)popupController?.popViewController(animated:true) // Popup will be dismissed if there is only one view controller in the popup view controller stackpopupController?.dismiss()

Push & Pop

Bottom sheet style
Objective-C

STPopupController *popupController = [[STPopupControlleralloc]initWithRootViewController:[ViewControllernew]];popupController.style = STPopupStyleBottomSheet;[popupControllerpresentInViewController:self];

Swift

letpopupController=STPopupController(rootViewController: viewController)popupController.style=.bottomSheetpopupController.present(in:self)

Bottom Sheet

Customize popup transition style
Objective-C

#pragma mark - STPopupControllerTransitioning- (NSTimeInterval)popupControllerTransitionDuration:(STPopupControllerTransitioningContext *)context{return context.action == STPopupControllerTransitioningActionPresent ?0.5 :0.35;}- (void)popupControllerAnimateTransition:(STPopupControllerTransitioningContext *)context completion:(void (^)())completion{// Popup will be presented with an animation sliding from right to left.    UIView *containerView = context.containerView;if (context.action == STPopupControllerTransitioningActionPresent) {        containerView.transform =CGAffineTransformMakeTranslation(containerView.superview.bounds.size.width - containerView.frame.origin.x,0);                [UIViewanimateWithDuration:[selfpopupControllerTransitionDuration:context]delay:0usingSpringWithDamping:1initialSpringVelocity:1options:UIViewAnimationOptionCurveEaseInOutanimations:^{            context.containerView.transform =CGAffineTransformIdentity;        }completion:^(BOOL finished) {completion();        }];    }else {        [UIViewanimateWithDuration:[selfpopupControllerTransitionDuration:context]delay:0options:UIViewAnimationOptionCurveEaseOutanimations:^{            containerView.transform =CGAffineTransformMakeTranslation(-2 * (containerView.superview.bounds.size.width - containerView.frame.origin.x),0);        }completion:^(BOOL finished) {            containerView.transform =CGAffineTransformIdentity;completion();        }];    }}// Use custom transitioning in popup controllerSTPopupController *popupController = [[STPopupControlleralloc]initWithRootViewController:viewController];popupController.transitionStyle = STPopupTransitionStyleCustom;popupController.transitioning = self;[popupControllerpresentInViewController:self];

Swift

// MARK: STPopupControllerTransitioningfunc popupControllerTransitionDuration(_ context:STPopupControllerTransitioningContext)->TimeInterval{return context.action==.present?0.5:0.35}func popupControllerAnimateTransition(_ context:STPopupControllerTransitioningContext, completion:@escaping()->Void){    // Popup will be presented with an animation sliding from right to left.letcontainerView= context.containerViewif context.action==.present{        containerView.transform=CGAffineTransform(translationX: containerView.superview!.bounds.size.width- containerView.frame.origin.x, y:0)UIView.animate(withDuration:popupControllerTransitionDuration(context), delay:0, usingSpringWithDamping:1, initialSpringVelocity:1, options:.curveEaseInOut, animations:{            containerView.transform=.identity}, completion:{ _incompletion()});}else{UIView.animate(withDuration:popupControllerTransitionDuration(context), delay:0, usingSpringWithDamping:1, initialSpringVelocity:1, options:.curveEaseInOut, animations:{            containerView.transform=CGAffineTransform(translationX:-2*(containerView.superview!.bounds.size.width- containerView.frame.origin.x), y:0)}, completion:{ _in            containerView.transform=.identitycompletion()});}}// Use custom transitioning in popup controllerletpopupController= let popupController=STPopupController(rootViewController: viewController)popupController.transitionStyle=.custompopupController.transitioning=selfpopupController.present(in:self)

Blur background
Objective-C

STPopupController *popupController = [[STPopupControlleralloc]initWithRootViewController:[PopupViewController1new]];if (NSClassFromString(@"UIBlurEffect")) {    UIBlurEffect *blurEffect = [UIBlurEffecteffectWithStyle:UIBlurEffectStyleDark];    popupController.backgroundView = [[UIVisualEffectViewalloc]initWithEffect:blurEffect];}

Swift

letpopupController= let popupController=STPopupController(rootViewController: viewController)ifNSClassFromString("UIBlurEffect")!=nil{letblurEffect=UIBlurEffect(style:.dark)    popupController.backgroundView=UIVisualEffectView(effect: blurEffect)}

Action of tapping on area outside of popup
Objective-C

[popupController.backgroundViewaddGestureRecognizer:[[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(backgroundViewDidTap)]];

Swift

popupController.backgroundView?.addGestureRecognizer(UITapGestureRecognizer(target:self, action: #selector(backgroundViewDidTap)))

Customize UI
Objective-C

[STPopupNavigationBarappearance].barTintColor = [UIColorcolorWithRed:0.20green:0.60blue:0.86alpha:1.0];[STPopupNavigationBarappearance].tintColor = [UIColorwhiteColor];[STPopupNavigationBarappearance].barStyle = UIBarStyleDefault;[STPopupNavigationBarappearance].titleTextAttributes = @{NSFontAttributeName: [UIFontfontWithName:@"Cochin"size:18],NSForegroundColorAttributeName: [UIColorwhiteColor] };    [[UIBarButtonItemappearanceWhenContainedIn:[STPopupNavigationBarclass],nil]setTitleTextAttributes:@{NSFontAttributeName:[UIFontfontWithName:@"Cochin"size:17] }forState:UIControlStateNormal];

Swift

STPopupNavigationBar.appearance().barTintColor=UIColor(red:0.2, green:0.6, blue:0.86, alpha:1)STPopupNavigationBar.appearance().tintColor=.whiteSTPopupNavigationBar.appearance().barStyle=.defaultSTPopupNavigationBar.appearance().titleTextAttributes=[.font:UIFont(name:"Cochin", size:18)??.systemFont(ofSize:18),.foregroundColor:UIColor.white,]UIBarButtonItem.appearance(whenContainedInInstancesOf:[STPopupNavigationBar.self]).setTitleTextAttributes([.font:UIFont(name:"Cochin", size:18)??.systemFont(ofSize:18),], for:.normal)

Customize UI

Auto-reposition when keyboard is showing up
This is default behavior.
Auto-reposition

Drag to dismiss
This is default behavior.
Drag to dismiss

Handle orientation change
This is default behavior.
Orientation change

Please checkout the example project for more details.

About

STPopup provides STPopupController, which works just like UINavigationController in popup style, for both iPhone and iPad. It's written in Objective-C and compatible with Swift.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp