How to apply mask to backend view? - ios

I am trying to apply mask to backend view but am unable reach my expectation. I want the view should be like showing in the below image.
I tried to implement in my own way but the mask view also comes up from bottom. When we click on iCloud option in iPad immediately the backend view becomes in gray color and the custom view comes up from bottom. I want same feature needs to be implemented in my application. Please help me. Thanks in advance.

I strongly suggest you use this nice and tidy git code
https://github.com/jmascia/KLCPopup
KLCPopup really does a very nice job in implementing modal views with animations, blur, fade, etc.
Very easy to set up and use, it's litreally just
" choose your view "
" choose where you want it "
" Add effects if you want some "
"there you go "
have fun ;)

Follow below steps to achieve your requirements-
1) Create a BaseView & Add a CustomView on the center of the BaseView.
2) Set the background color of BaseView as black with 50% opacity.
3) Keep the actual transform of the CustomView in a variable as
CGAffineTransform m_actualTransformOfCustomView =
m_customView.transform;
4) Scale the CustomView to a small 0.01 , 0.01 using
self.m_customView.transform = CGAffineTransformScale(m_actualTransformOfCustomView, 0.01, 0.01);
4) Use [UIView amimateWithDuration:] api to change the transform of the custom view to original as-
[UIView animateWithDuration:0.5f
delay:0
options:UIViewAnimationOptionCurveEaseOut
animations:^
{
self.m_customView.transform = CGAffineTransformScale(m_actualTransformOfCustomView, 1.0, 1.0);
}
completion:^(BOOL finished)
{
}
];
}

My own way is working now properly. Here is the code snippet. Enjoy!
-(IBAction)show:(id)sender{
customView = [[UIView alloc] initWithFrame:self.view.frame]; // Mask View
customView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3f];
[self.view addSubview:customView];
// customConfigurationView // PopUp view
CGRect frameCustmVw = customConfigurationView.frame;
frameCustmVw.origin.y = self.view.frame.size.height;
frameCustmVw.origin.x = 134;
customConfigurationView.frame = frameCustmVw;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
frameCustmVw.origin.y = 200;
customConfigurationView.frame = frameCustmVw;
[self.view addSubview:customConfigurationView];
[UIView commitAnimations];
[txtClientID becomeFirstResponder];
}
-(IBAction)remove:(id)sender{
[customView removeFromSuperview]; // Remove mask view
CGRect CustmFrame = customConfigurationView.frame;
CustmFrame.origin.y = 200;//self.view.frame.size.height - customConfigurationView.frame.size.height;
customConfigurationView.frame = CustmFrame;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
CustmFrame.origin.y = self.view.frame.size.height;
customConfigurationView.frame = CustmFrame;
[UIView commitAnimations];
}

oky , my answer regarding the way how settings app doing this, it is simple ... they are just presenting a navigation controller thats all, for example
just create a view controller subclass for example (i named it as TestViewController) and set it size to freeform in attribute inspector and change its frame's width and height to your required values and add view components
it will show the view controller with width and height of 540*620 with your animation
that's all
- (IBAction)presentAction:(id)sender
{
TestViewController *testVc = [[TestViewController alloc]initWithNibName:#"TestViewController" bundle:nil];
UINavigationController *aNavController = [[UINavigationController alloc] initWithRootViewController:testVc];
aNavController.modalPresentationStyle = UIModalPresentationFormSheet;
aNavController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:aNavController animated:YES completion:nil];
}

Related

how to show Container View ViewController and hide Container view ViewController

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!

issue while using navigation bar and UITextField

I am facing a weird issue.
I have three UITextField and when keyboard overlaps the screen i am moving up the screen using code:
- (void)textFieldDidBeginEditing:(UITextField *)textField {
if(self.view.frame.size.height==568 && textField==txtVerifyPassword)
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
self.view.center = CGPointMake(originalCenter.x,originalCenter.y-100);
}
else if(self.view.frame.size.height==568 && textField==txtPassword)
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
self.view.center = CGPointMake(originalCenter.x,originalCenter.y-20);
}
}
and I am moving to original position using:
- (void)textFieldDidEndEditing:(UITextField *)textField{
self.view.center = CGPointMake(originalCenter.x,originalCenter.y);
}
Original Center in DidLoad:
- (void)viewDidLoad {
[super viewDidLoad];
originalCenter = self.view.center;
// Do any additional setup after loading the view.
}
I am adding navigation Bar Programmatically like this:
[self.navigationController setNavigationBarHidden:NO];
self.navigationItem.title = #"Demo";
UIColor *bg = [UIColor colorWithRed:9/255.0f green:161/255.0f blue:12/255.0f alpha:1.0f];
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
// iOS 6.1 or earlier
self.navigationController.navigationBar.tintColor = bg;
self.navigationController.navigationBar.titleTextAttributes = #{NSForegroundColorAttributeName: [UIColor whiteColor]};
} else {
// iOS 7.0 or later
self.navigationController.navigationBar.barTintColor = bg;
self.navigationController.navigationBar.translucent = NO;
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
self.navigationController.navigationBar.titleTextAttributes = #{NSForegroundColorAttributeName: [UIColor whiteColor]};
}
When I remove navigation the every thing works great.
But when i add it i am getting two issues:
Extra Black Space at bottom ( View doesn't go back to its original Position)
When I swipe up or down navigation bar hides (don't know why this happens)
Just use TPKeyboardAvoidingScrollView and you are good to go. Its easy and simple to use. you can easily achieve what you are trying to achieve here.
Usage :
For use withUITableViewController classes, drop TPKeyboardAvoidingTableView.m and TPKeyboardAvoidingTableView.h into your project, and make yourUITableView aTPKeyboardAvoidingTableView in the xib.
If you're not using a xib with your controller, i know of no easy way to make itsUITableView a custom class: The path of least resistance is to create a xib for it.
For non-UITableViewControllers, drop theTPKeyboardAvoidingScrollView.m andTPKeyboardAvoidingScrollView.h source files into your project, pop aUIScrollView into your view controller's xib, set the scroll view's class toTPKeyboardAvoidingScrollView, and put all your controls within that scroll view.
You can also create it programmatically, without using a xib - just use theTPKeyboardAvoidingScrollView as your top-level view.

UIView transitionWithView animating property change: slide in from right?

I have a readonly UITextView, and I'm updating the text.
When the new text appears, I want it to animate as follows: New text slides in from the right, as the old text slides offscreen toward the left side.
Is it possible to do this with transitionWithView? If not, what's the best way to do it? I can make it do a CrossDissolve, but that's not the animation I'm looking for:
[UIView transitionWithView:self.storyTextView
duration:0.5
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
[self.storyTextView setText:withStory.storyText];
}
completion:nil];
The reason for insisting on the right to left animation is because eventually I want the user to be able to trigger it by swiping toward the left on the UITextView.
CATransition will allow you to do this, with a transition type of 'push' and a subtype of 'from right'. It's very straightforward to use:
CATransition *transition = [CATransition new];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
// Make any view changes
self.textView.text = newText;
// Add the transition
[self.textView.layer addAnimation:transition forKey:#"transition"];
Note that this, while it's what you've asked for, won't fit nicely with a gesture without some extra tinkering - to tie it to a gesture you'd need to do something like set the layer speed to 0 and the manually update the progress of the animation to match your gesture.
What about just using UIView animateWithDuration and slide the one textView to the right while sliding a new textView from the left. Here is an example just have to work out the positions. Let me know if this is what you were looking to do.
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
self.textView2.frame = CGRectMake(1000.0,self.textView1.frame.origin.y,self.textView2.frame.size.width,self.textView2.frame.size.height);
}
- (IBAction)animate:(id)sender {
[UIView animateWithDuration:0.5 animations:^{
self.textView1.frame = CGRectMake(-200.0,self.textView1.frame.origin.y,self.textView1.frame.size.width,self.textView1.frame.size.height);
[UIView animateWithDuration:0.5 animations:^{
self.textView2.center = (CGPointMake(200, 200));
}];
}];
}
You can also try something like this.
You can create a containerView for your text view and then change the coordinates using UIView animations to give it a slide from right to left.
Please see code below.
First declare a container view and the make the required text view its subview.
In .h
#property (strong, nonatomic)IBOutlet UIView *containerView;
#property (strong, nonatomic)IBOutlet UITextView *childTextView; //I have set it as subview in xib
In .m make sure to set the following in viewDidLoad or in Xib
self.containerView.clipsToBounds = YES;
Gestures
UISwipeGestureRecognizer *recog = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(changeText)];
recog.direction = UISwipeGestureRecognizerDirectionLeft;
[self.containerView addGestureRecognizer:recog];
Beautification (for this you would need QuartzCore/QuartzCore.h)
self.containerView.layer.borderWidth = 1.0f;
self.containerView.layer.borderColor = [UIColor lightGrayColor].CGColor;
self.containerView.layer.cornerRadius = 5.0f;
To the Point
- (void)changeText
{
[UIView animateWithDuration:0.3f animations:^(void){
CGRect endPos = self.childTextView.frame;
endPos.origin.x -= endPos.size.width; //Move it out of the view's frame to the left
self.childTextView.frame = endPos;
} completion:^(BOOL done){
CGRect startPos = self.childTextView.frame;
startPos.origin.x += (2*startPos.size.width);// this will take it to the right.
self.childTextView.frame = startPos;
self.childTextView.text = #"Changed text";
[UIView animateWithDuration:0.2f animations:^(void){
CGRect displayPos = self.childTextView.frame;
displayPos.origin.x -= displayPos.size.width; // To compensate for the double +ve on top
self.childTextView.frame = displayPos;
}];
}];
}

How do I animate my subviews on adding them?

I have developed a font selection that utilizes UIPickerView and UIToolbar, which are both added on touching a UIButton.
But they just kind of pop in which looks sloppy.
is there a way to animate them?
here is the method that adds them (it's called on clicking the button) :
-(void)showPicker
{
[self.view addSubview:_fontPicker];
[self.view addSubview:pickerTB];
}
You can animate them in a couple of ways, but probably the easiest is to just fade them in.
Fade In
[someView setAlpha:0]
[self.view addSubview:someView];
[UIView beginAnimations:#"FadeIn" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
[someView setAlpha:1];
[UIView commitAnimations];
Fade Out
float fadeDuration = 0.5;
[UIView beginAnimations:#"FadeOut" context:nil];
[UIView setAnimationDuration:fadeDuration ];
[UIView setAnimationBeginsFromCurrentState:YES];
[someView setAlpha:0];
[UIView setAnimationDidStopSelector:#selector(removeView)];
[UIView commitAnimations];
-(void) removeView {
[someView removeFromSuperview];
}
Something as simple as that.
Depends on what type of animation you want to use. For example, this would look like dissolve.
Anyways look into UIView animateWithDuration...
pickerTB.alpha = _fontPicker.alpha = 0;
[self.view addSubview:_fontPicker];
[self.view addSubview:pickerTB];
[UIView animateWithDuration:1 animations:^{_fontPicker.alpha = 1; pickerTB.alpha = 1}];
You could use transforms or change frame origins to make the views fly in from positions outside the screen too. In that case, inside the animations block, specify the new on screen position. You can do this in two ways, change the frame with an updated origin or apply a CGAffineTransformMakeTranslation(dx,dy)
You need to add the subview with a frame value that is where you want the animation to begin from (off-screen?) then change the frame value inside your animation block. The frame will change over the duration, causing the appearance of movement. The view must already be a subview - I don't believe adding a subview is something you can animate, it makes no sense.
-(void) showPicker{
[self.view addSubview: _fontPicker];
_fontPicker.frame = CGRectMake(0, 0, 120, 40);// somewhere offscreen, in the direction you want it to appear from
[UIView animateWithDuration:10.0
animations:^{
geopointView.frame = // its final location
}];
}
Initially set your picker view frame and tool bar frame like this one..
-(void)viewDidLoad
{
[super viewDidLoad];
pickerTB.frame = CGRectMake(0,568,320,44);
fontPicker.frame = CGRectMake(0, 568, 320, 216);
}
-(void)showPicker
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.30];
if(isiPhone5)
{
pickerTB.frame = CGRectMake(0,288,320,44);
fontPicker.frame = CGRectMake(0, 332, 320, 216);
}else{
pickerTB.frame = CGRectMake(0,200,320,44);
fontPicker.frame = CGRectMake(0,244, 320, 216);
}
[UIView commitAnimations];
}

Slide UIViews like in The Magazine

I wonder if somebody here knows how I can slide the views in my application. When I'm in a view, I want to slide to another view like in "The Magazine". (see image)
Hope somebody can help me.
Image:
http://bildr.no/view/1361377
As far as I know, there is no "canned" transition that does a slide over. I've implemented it like this:
-(void)SlideInController:(RDSlideController *) next {
next.presentingVC = self;
next.view.frame = CGRectMake(self.view.frame.origin.x + 320, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
[self.view.window addSubview:next.view];
[UIView animateWithDuration:slideTime animations:^{
next.view.frame = self.view.frame;
} completion:^(BOOL finished) {
self.view.window.rootViewController = next;
}];
}
-(void)SlideOut {
RDSlideController *prev = self.presentingVC;
prev.view.frame = self.view.frame;
[self.view.window insertSubview:prev.view belowSubview:self.view];
[UIView animateWithDuration:slideTime animations:^{
self.view.frame = CGRectMake(self.view.frame.origin.x + 320, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
} completion:^(BOOL finished) {
self.view.window.rootViewController = prev;
}];
}
In this example, I made a controller class (RDSlideController) that was the superclass of my other controllers, so that they would all have the presentingVC property and access to the various slide in and out (and up and down) methods that I wrote. This should give you an idea of how to do this.
Take a look at UIPageViewController
Here is a link to the doc. Starting with iOS5, it supports the page curl transition. And in iOS6, they added the slide like you have on your screenshot.
If you need to support earlier version, you will most likely need to create your own animation (using CAAnimation).

Resources