I want to create a custom popup and I want to generate a code dynamically without using UI drag and drop.
The view should look like:
I am using the following code to call the popup :
CustomPopUp *cp = [[CustomPopUp alloc]init];
cp.view.frame = CGRectMake(0.0, 0.0, 300, 300);
KLCPopup* popup = [KLCPopup popupWithContentView:cp.view];
[popup show];
The custom popup code looks like:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.gaScreenName = #"Login";
if (firstPageLoad) {
return;
}
LinearLayoutPageHeading *heading = [[LinearLayoutPageHeading alloc] initWithText:#"Sign in." maxWidth:[LayoutValues getMaxWidthClipped]];
[self.topContainerContent addObject:heading];
NSString *content = #"New patient? Register here.";
LinearLayoutLinksViewItem *contentItem = [[LinearLayoutLinksViewItem alloc] initLinksViewWithText:content font:[PPFonts genericParagraphFont] maxWidth:[LayoutValues getMaxWidthClipped] links:nil];
[self.topContainerContent addObject:contentItem];
LinearLayoutTextInputAndLabel *emailField = [[LinearLayoutTextInputAndLabel alloc] initWithLabelText:#"EMAIL ADDRESS" maxWidth:[LayoutValues getMaxWidthClipped]];
emailField.textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
LinearLayoutButton *continueButton = [[LinearLayoutButton alloc] initWithText:#"SIGN IN" maxWidth:[LayoutValues getMaxWidthClipped] url:nil type:#"primary"];
[self.topContainerContent addObject:continueButton];
LinearLayoutLinksViewItem *noticesPar = [[LinearLayoutLinksViewItem alloc] initLinksViewWithText:#"By clicking Sign In you agree to our Consent to Telehealth, Consent to Request Medical Services, Privacy Policy and Terms of Use." font:[PPFonts signInTermsParagraph] maxWidth:[LayoutValues getMaxWidthClipped] links:nil];
noticesPar.padding = CSLinearLayoutMakePadding(0, noticesPar.padding.left, 10, noticesPar.padding.right);
[self.topContainerContent addObject:noticesPar];
[self renderPageContainers];
firstPageLoad = YES;
}
#end
I am using custom created view controller but am getting a blank popup.
Is there a way to get the above layout using standard UIViewController? I am new to iOS development and have not dynamically generated UI views so far.
If CustomPopUp is a viewcontroller, you need to instantiate it with a storyboard vc or a xib, something like this:
//For xib:
let a = UIViewController(nibName: "CustomPopUp", bundle: NSBundle.mainBundle()) as! CustomPopUp
//For storyboard
let b = UIStoryboard(name: "main", bundle: NSBundle.mainBundle()).instantiateViewControllerWithIdentifier("CustomPopup") as! CustomPopUp
Not totally sure how you are dealing with this, but I recommended you to create a custom view, not a custom viewcontroller, easier to create and use
Create a custom View with xib and add subview of your current view contoller.
make property instance of popupView
in your viewController.h
#property (strong,nonatomic) YourPopUpViewClass *popupView;
in your viewController.m
setUp Popup View
self.popUpView.hidden = YES;
self.popUpView.frame = [UIScreen mainScreen].bounds;
self.popUpView.alpha = 0.0;
self.popUpView.delegate = self; // for hide PopupView and Other Functinality if you need
[self.view addSubview:self.popUpView];
Now Display On Button Click With Animation
-(void)showPopupView{
self.popUpView.hidden = No;
[UIView animateWithDuration:0.0 delay:0
options:UIViewAnimationOptionCurveEaseInOut
animations:^ {
self.popUpView.alpha = 0.0
}completion:^(BOOL finished) {
[UIView animateWithDuration:0.3
delay:0
options:UIViewAnimationOptionCurveEaseInOut
animations:^ {
self.popUpView.alpha = 1.0
}completion:^(BOOL finished) {
}];
}];
}
And Hide like this
-(void)hidePopupView {
self.popUpView.hidden = No;
[UIView animateWithDuration:0.3 delay:0
options:UIViewAnimationOptionCurveEaseInOut
animations:^ {
self.popUpView.alpha = 0.0
}completion:^(BOOL finished) {
self.popUpView.hidden = Yes;
}];
}
hope this will help you.
Here is the good example for custom popup. Custom PopUP View. Just add your container in it.
Found a feasible solution. I used a third party library to achieve the result KLCPopup
However I have a new question. My popup does have a custom view but it comes from a separate class (view). How do I make my current view change based on input to the popup view? Can I have links to a few useful documents. I do not need code, just need to be pointed in the right direction.
Related
I am new in iOS and I am facing a problem regarding to create slide out menu.
I searched and found the example but all are for storyboard and which I found in xib are called on AppDelegate Class.
I need to create a Slide out menu in xib which should be call after login.
Thanks in Advance!
The best example of side bar menu is SWRevealViewController. This library is easy to use and its easy to understand.
This below work for me well...try in your code.
_parentView is your custom slide out view and _rightView (UIButton )is used to dismiss these custom slide out view. you just initialize these two property
#property (strong,nonatomic) UIView *parentView;
#property (strong,nonatomic) UIButton *rightView;
-(void)slideView
{
if(![_parentView isDescendantOfView:app.navController.view])
{
[self showMenu];
}
else
{
[self hideMenu];
}
}
-(void)showMenu
{
int width=[[UIScreen mainScreen]bounds].size.width;
int height=[[UIScreen mainScreen]bounds].size.height;
_parentView =[[UIView alloc]initWithFrame:CGRectMake(0-(width-70), 0, width-70, self.navigationController.view.frame.size.height)];
[_parentView setBackgroundColor:[UIColor lightTextColor]];
[app.navController.view addSubview:_parentView];
_rightView=[[UIButton alloc]initWithFrame:CGRectMake(0,80, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-80)];
_rightView.alpha=0.7;
[_rightView addTarget:self action:#selector(hideMenu) forControlEvents:UIControlEventTouchUpInside];
if(_parentView.frame.origin.x <0)
{
[self performSelector:#selector(showSideMenu) withObject:nil afterDelay:0.2];
}
}
-(void)showSideMenu{
if(_parentView.frame.origin.x <0)
{
[UIView animateWithDuration:0.5 animations:^{
[UIView animateWithDuration:0.7 animations:^{
[self.view addSubview:_rightView];
_rightView.backgroundColor=[UIColor blackColor];
}];
CGRect frame = _parentView.frame;
frame.origin.x =0;
_parentView.frame = frame;
CGRect rightFrame=self.view.frame;
rightFrame.origin.x=_parentView.frame.size.width;
self.view.frame=rightFrame;
CGRect fram1=app.navController.navigationBar.frame;
fram1 .origin.x =_parentView.frame.size.width;
app.navController.navigationBar.frame =fram1 ;
} completion:^(BOOL finished) {
}];
}
}
-(void)hideMenu
{
if(_parentView.frame.origin.x == 0)
{
[UIView animateWithDuration:0.3 animations:^{
CGRect frame = _parentView.frame;
frame.origin.x=-_parentView.frame.size.width;
_parentView.frame = frame;
CGRect fram=self.view.frame;
fram .origin.x=0;
self.view.frame =fram ;
CGRect fram1=app.navController.navigationBar.frame;
fram1 .origin.x =0;
app.navController.navigationBar.frame =fram1 ;
} completion:^(BOOL finished) {
[_rightView removeFromSuperview];
[_parentView removeFromSuperview];
}];
}
}
Thank you...!!!
PUSH FROM NORMAL VIEW CONTROLLER TO SW VIEW CONTROLLER
UIStoryboard*Storyboard=[AppDelegate storyBoardType];
SidebarViewController *sidebarmemu =(SidebarViewController*)[Storyboard instantiateViewControllerWithIdentifier:#"SidebarController"];
tbTBC*tabbarController=(tbTBC*)[Storyboard instantiateViewControllerWithIdentifier:#"tbTBCId"];
SWRevealViewController *revealController;
UINavigationController *frontNavigationController;
UINavigationController *rearNavigationController;
frontNavigationController =[[UINavigationController alloc]initWithRootViewController:tabbarController];
rearNavigationController =[[UINavigationController alloc]initWithRootViewController:sidebarmemu];
revealController = [[SWRevealViewController alloc] initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];
revealController.delegate = self;
self.swcontroller =revealController;
self.view.window.rootViewController =self.swcontroller;
WITH THE HELP OF THIS CODE YOU CAN GET BOTH TAB BAR AS WELL AS SIDE BAR
I want to show ContainerView's view controller as like this
I use the following Code and it shows as i want
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: 0.8];
if (_addLinkQuestionView.isHidden == YES)
{
_addLinkQuestionView.hidden = NO;
_addLinkQuestionView.alpha = 1.0;
}
else
{
_addLinkQuestionView.alpha = 0.0;
_addLinkQuestionView.hidden = YES;
}
[UIView commitAnimations];
but Upon a click on blurr area, i want to hide container view. that area is the UIButton. I use the following code, but it does nothing.
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: 0.8];
_addLinkQuestionView.alpha = 0.0;
_addLinkQuestionView.hidden = YES;
[UIView commitAnimations];
Any Help. Thanx in advance.
Essentially it seems you need to show a alertview behaviour where all the ui from app is disabled while only the content in the dialog is enabled.
Add a public method like showOverlayView:(UIView*)v to your app delegate
On this method create a view, set alpha and add it to keywindow.
Now add the passed view to keywindow and calculate and set
its center property.
Alternatively you could use a library like MJPopupViewController or SLPopupViewController to do the job for you.
The correct way to do this :
1- New File -> UIView -> rename it to addLinkQuestionView
2- New File -> obj c class -> rename it to addLinkQuestionView
Now u have a xib,a .h and a .m
3- Go to the xib and in file's owner select your addLinkQuestionView u created in step 2
4- Design the xib as the picture link you posted and link up appropriate outlets to addLinkQuestionView.h
5- For initialization of your uiview in .h do this :
#import "addLinkQuestionView.h"
#implementation addLinkQuestionView
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
// Initialization code.
[[NSBundle mainBundle] loadNibNamed:#"addLinkQuestionView" owner:self options:nil];
self.vuComplete.frame = CGRectMake(self.vuComplete.frame.origin.x, self.vuComplete.frame.origin.y, self.frame.size.width, self.frame.size.height);
[self addSubview:self.vuComplete];
self.vuContainer.layer.cornerRadius = 5.0;
self.vuContainer.layer.borderWidth = 1.0/[UIScreen mainScreen].scale;
self.vuContainer.layer.borderColor = [[UIColor clearColor]CGColor];
self.vuContainer.alpha = 0.0;
[self layoutIfNeeded];
}
return self;
}
-(void)awakeFromNib
{
}
- (IBAction)onBackgroundTapDismissView:(id)sender {
[UIView animateWithDuration:0.5
animations:^{self.vuContainer.alpha = 0.0;}
completion:^(BOOL finished){ }];
[self removeFromSuperview];
}
Note : - (IBAction)onBackgroundTapDismissView can be a accomplished by dropping a uitapgesturerecognizer on your addLinkQuestionView's greyed background uiview so that tapping it can dismiss the entire uiview (vuComplete)
6- Then add this in your main view controller that is presenting this pop up like this :
A- import addLinkQuestionView.h first
B- add this code on your button action that you're clicking for presenting addLinkQuestionView:
addLinkQuestionView *popup = [[addLinkQuestionView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[UIView animateWithDuration:0.25
animations:^{popup. addLinkQuestionView.alpha = 1.0;}
completion:^(BOOL finished){ }];
[self.view addSubview:popup];
Have fun!
Alright so I am trying to create a slide out side view for navigation in my app, similar to Facebook and many others. I have that part working but the navigation controller doesn't respond to any touch events. I have a feeling this is because I am having my subclassed Navigation Controller add the child view controller and subview, instead of having the present view display the child. Here is the code I run on my "FeaturedViewController" that calls to "MainNavigationController" to add "MenuViewController" as a child of "MainNavigationController"
//ignoring compiler error as we know the parentViewController will be of type MainNavigationController at runtime.
MainNavigationController *main = self.parentViewController;
if (self.categories != nil)
main.categories = self.categories;
if (main.showingLeftPanel)
[main movePanelToOriginalPosition];
else
[main movePanelRight];
From there:
- (void)movePanelRight // to show left panel
{
UIView *childView = [self getLeftView];
//_leftPanelViewController.categories = self.categories;
[self.view sendSubviewToBack:childView];
[UIView animateWithDuration:SLIDE_TIMING delay:0 options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
_centerViewController.view.frame = CGRectMake(self.view.frame.size.width - PANEL_WIDTH, 0, self.view.frame.size.width, self.view.frame.size.height);
}
completion:^(BOOL finished) {
if (finished) {
//_centerViewController.leftButton.tag = 0;
}
}];
}
- (UIView *)getLeftView
{
// init view if it doesn't already exist
if (_leftPanelViewController == nil)
{
// this is where you define the view for the left panel
_leftPanelViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"MenuViewController"];
[self addChildViewController:_leftPanelViewController];
[self.view addSubview:_leftPanelViewController.view];
[_leftPanelViewController didMoveToParentViewController:self];
_leftPanelViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
}
_leftPanelViewController.categories = self.categories;
self.showingLeftPanel = YES;
// set up view shadows
[self showCenterViewWithShadow:YES withOffset:-2];
UIView *view = self.leftPanelViewController.view;
return view;
}
I have a single view App and want to show a new ViewController when pressing a nav bar button in the right hand side. I call this VC by this code:
- (IBAction)createEntryButton:(id)sender {
CreateEntryViewController *vc2 = [[CreateEntryViewController alloc] init];
[self presentViewController:vc2 animated:TRUE completion:nil];
}
This animation, however, brings the vc2 in from the bottom which seems counter-intuitive according to my UI. So my question is:
How can I make my vc2 appear from the right instead of the bottom with presentViewController?
Thanks.
the cleanest would be to use a navigationController for pushing and popping views..
if you are already in a NavigationController
[self.navigationCtroller pushViewController:vc2 animated:TRUE completion:nil]
if you aren't, adapt the code where your view controller is added to the window. If your VC is the rootWindowController and you are not using storyboarding, this is likely in your AppDelegate
if you use storyboards, adapt the storyboard so you are inside a navigation controller
ELSE if you don't want that for any reason: :) just manually animate in the 2. VC's view using [UIView animate:vc2.view ....]
written inline -- method names don't match but shows general approach:
UIView *v = vc2.view;
CGRect f = v.frame;
f.origin.x += self.view.frame.size.width; //move to right
v.frame = f;
[UIView animateWithDuration:0.5 animations:^{
v.frame = self.view.frame;
} completion:^(BOOL finished) {
[self presentViewController:vc2 animated:NO completion:nil];
}];
in the completion block present the view controller vc2 non-animated as you already did that yourself
This helped me,
- (void)presentNewViewController{
NewViewController *objNewViewController =[[NewViewController alloc]initWithNibName:#"NewViewController" bundle:nil];
UIView *tempNewVCView = [UIView new];
tempNewVCView = objNewViewController.view;
tempNewVCView.frame = self.view.frame;
CGRect initialFrame = self.view.frame;
initialFrame.origin.x = self.view.frame.size.width;
tempNewVCView.frame = initialFrame;
[self.view addSubview:tempNewVCView];
[UIView animateWithDuration:0.3 animations:^{
tempNewVCView.frame = self.view.frame;
} completion:^(BOOL finished) {
[self presentViewController:objNewViewController animated:NO completion:^{
}];
}];
}
I'm using a custom animation to present my view controllers. Here's the code:
-(void)launchCustomModal:(id)sender
{
UIButton *buttonClicked = (UIButton *)sender;
int selection;
selection = buttonClicked.tag;
[ticker removeFromSuperview];
ticker = nil;
if (selection == 3)
{
MyViewController *myVC = [[MyViewController alloc]initWithNibName:nil bundle:nil];
modalViewController= [[UINavigationController alloc]initWithRootViewController:myVC];
modalViewController.navigationBarHidden = YES;
[modalViewController setToolbarHidden:YES];
CGRect result = self.view.bounds;
result.origin.y = -result.size.height;
modalViewController.view.frame=result;
[self.view addSubview:modalViewController.view];
[UIView animateWithDuration:.375
animations:^{
modalViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
}
completion:^(BOOL finished) {
NSLog(#"Finished");
}];
}
return;
}
I've noticed this method makes for a very laggy transition. If I launch the VC in a normal modal, it works quite smoothly. Also, if I animate just a view independent of a view controller, it also works perfectly smoothly. I'm wondering if there is something about the VC that might be causing it to animate so poorly? If its a symptom of something I'm doing or if view controllers are just not meant to be handled this way, etc. Any input is greatly appreciated. Thanks!
It was the CALayer shadows. removed them and it worked fine.