Custom UIActivityViewController-like view that slides up and down - ios

Is there a way to subclass or customize UIActivityViewController to create a sort of custom view? For example, see the image below from the app Overcast. I want to create a view similar to that, where if you tap a button, the view pops up and when you tap outside of the view, it slides back down.

Why not use an UIView ? Set it's initial frame's y value to -self.customView.frame.size.height and animate it's frame to the normal position using [UIView animateWithDuration]
-(void)showCustomView{
[self.customview setFrame:CGRectMake(0, -self.customView.frame.size.height, self.view.bounds.size.height+self.customView.frame.size.width, self.customView.frame.size.height)];
[UIView animateWithDuration:0.25 animations:^{
[self.customView setFrame:CGRectMake(0, -self.view.frame.size.height, self.view.bounds.size.height-self.customView.frame.size.width, self.customView.frame.size.height)];
}];
}
-(void)hideCustomView{
[UIView animateWithDuration:0.25 animations:^{
[self.customView setFrame:CGRectMake(0, -self.customView.frame.size.height, self.customView.bounds.size.height+self.customView.frame.size.width, self.customView.frame.size.height)];
}];
}
Add an UITapGestureRecognizer and call hideCustomView when tapped outside the customView

Related

Showing UIPickerView when cell is selected

For my app I’m implementing in-app settings using tableView with Dynamic prototype cells. Inside cell I’m showing main title and sub title. What I would like to achieve is when user clicks on one of the cells (that represents specific settings) the pickerView will slide from the bottom of the screen showing the options that user can pick. I’ve seen few tutorials where this pickerView is presented inside a cell as it is e.g. in iOS calendar app but I don’t need that – all will be fine if it will slide from the bottom actually in a same way as it is when you are having pickerView as inputView for your text field (e.g. textField.inputView = pickerView) and click to the text field. I appreciate any help you can provide guys! Thanks in advance!
You can create a custom view xib in which you can have pickerView,when user click on cell just show the custom view with animation.
viewPicker = CGRectMake(0, 490, 320, 460);
For the animation from bottom to top add below:
[UIView animateWithDuration:0.5
delay:0.1
options: UIViewAnimationCurveEaseIn
animations:^{
viewPicker.frame = CGRectMake(0, 0, 320, 460);
}
completion:^(BOOL finished){
}];
[self.view addSubview:viewPicker];
For removing the view
[UIView animateWithDuration:1.5
delay:0.5
options: UIViewAnimationCurveEaseIn
animations:^{
viewPicker.frame = CGRectMake(0, 490, 320, 460);
}
completion:^(BOOL finished){
if (finished)
[viewPicker removeFromSuperview];
}];

Popup the uiview in button click in iOS

I have one mainview UIViewController. in that view put one UIView name loginview with small size(self.loginview.frame = CGRectMake(4,166,306,153);
In mainview uiviewcontroller i put one button if i click that button loginview want to display like popup... how can i achieve this help me here code.
- (IBAction)Regbtn_click:(id)sender
{
//in this place i want to write the code for login view want come like popup.. help me..
loginview.hidden=false
}
Instead of setting hidden property of your loginview, set its alpha to 0.0 and you can use this animation
-(IBAction)Regbtn_click:(id)sender {
//[self.view addSubview:self.loginView]; if your loginview is not added to view, if it is, ignore this line
[UIView animateWithDuration:0.5 animations:^{
self.loginView.alpha = 1.0; //to display loginview
} completion:^(BOOL finished) {
}];
}
You can animate the view with two animations:
1) scaling
2) fading
View Controller
->Button (Viewcontroller Child)
->LoginWrapperView (Viewcontroller Child)
->black-transparent View (LoginWrapperView Child)
->login View (LoginWrapperView Child)
Add black semi-transparent view (with opacity of 0.2 i think) on screen and above that place your loginView and set its opacity to 0.
[LoginWrapperView SetHidden:YES];
[loginView SetAlpha:0];
[loginView SetFrame:CGRectMake(0,0,0,0)];
Now when you click on the button,
[LoginWrapperView SetHidden:NO];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.2];
[UIView setAnimationDelegate:self];
//position on screen
[loginView SetAlpha:1];
[loginView SetFrame:<your CGRect goes here>];
[UIView setAnimationDidStopSelector:#selector(finishAnimation:finished:context:)];
//animate off screen
[UIView commitAnimations];
Then handle Tap Getsture on semi-transparent view to close or hide the same by reversing the same animation with different values.
You can push your view modally or use a nice library like MZFormSheetController that do just that.
Here's how it looks like
It is simple just present your view. You could also make the background transparent and many other customization.
YourPopupViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"PopupView"];
-(IBAction)buttonClick{
// present form sheet with view controller
[self mz_presentFormSheetController:vc animated:YES completionHandler:^(MZFormSheetController *formSheetController) {
//do your login stuff
}];
}

Hidding view with table scroll

I'm searching for idea how to implement a table view with moving view on top of it.
So the idea is something similar to navBar in facebook app. When you scroll up this (red) view is moving up and hiding, when you scroll up its going up and when you scroll down its revealed. This is not nav bar so most of the pods I've found are not working in this situation. This cannot be tableView header or section header as well.
You need added this view above table:
[self.tableView.superview insertSubview:view aboveSubview:self.tableView]
Or you can do it in storyboard.
When you table scroll down hide view, when up show.
[view setHidden:YES];
Also u could change table inset to the top of the superview.
self.tableView.contentInset = self.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(self.tableView.contentInset.top -, self.tableView.contentInset.left, self.tableView.contentInset.bottom, self.tableView.contentInset.right);
I think fast way to do it use gesture recognizers to recognize reveal and hide actions and than you can use methods like below,
[UIView animateWithDuration:0.5 animations:^{
[attachedView setAlpha:0.0f];
} completion:^(BOOL finished) {
[attachedView setHidden:YES];
}];
and for reveal attached view
[UIView animateWithDuration:0.5 animations:^{
[attachedView setAlpha:1.0f];
} completion:^(BOOL finished) {
[attachedView setHidden:YES];
}];
methods will help you to hide and reveal views gently.
Take a look at this library, it does exactly what you want to do
https://github.com/telly/TLYShyNavBar

How to flip a view with a label on the front side and another label on the back side - see image

How can I flip a view with a label on the front side and another label on the back side when a button is clicked? Something that looks like the image below.
What would be the logic to create this effect?
Thanks
EDIT:
Sorry about the confusion but please note that I'm just talking about a view not ViewControllers, this effect will happen within the same viewController. I have updated the image to reflect that the view I'm talking about is a subView inside the main view.
I too had something very similar situation, on click of a button on ViewController1 I have to move to another ViewController2. I used this code,
//code this in ViewController1
-(IBAction)flipView:(id)sender
{
ViewController2 *view2 = [[ViewController2 alloc] initWithNibName:#"ViewController2" bundle:nil];
[UIView beginAnimations:#"animation" context:nil];
[UIView setAnimationDuration:1.0];
[[self navigationController] pushViewController:view2 animated:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
[view2 release];
}
//code this in ViewController2 on click of back button
-(IBAction)flipView:(id)sender
{
[UIView beginAnimations:#"animation" context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
[[self navigationController] popViewControllerAnimated:YES];
[UIView commitAnimations];
}
But in this code I am using 2 classes, if it is fine to you, use this code. Hopes it solves your problem to some extent.
What you can do is use two UIViews, one for the first side, one for the second side.
Show the first view, hide the second view, and set the second view's frame to have a width of 0.
Then, when your first view is visible, animate its frame to have a width equal to 0. Hide the first view, unhide the second view, and animate the second view's frame to the desired frame.
Edit : This does not appear to work well if you have labels in your views, as this is a 2D flip. Sorry about that. #Maverick's answer could work pretty well in your case.
Call this method in your viewController, your viewController view flips and viewController life cycle method calls and simply change the image of UIImageView you want to display in
-(void)viewdidload method.
[UIView beginAnimations: #"Showinfo"context: nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
UIView *parent = self.view.superview;
[self.view removeFromSuperview];
self.view = nil; // unloads the view
[parent addSubview:self.view]; //reloads the view from the nib
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
Please vote up if you find it helping

Animating two UIView subviews at the same time does not work

For some reason i am not able two animate two subviews postion. I have wrote the following
[self addChildViewController:self.photosViewController];
[self.photosViewController.view setFrame:CGRectMake(0, -self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height)];
[self.view addSubview:self.photosViewController.view];
[UIView animateWithDuration:1 delay:0
options:UIViewAnimationOptionCurveEaseIn
animations:^{
[self.stepsView setFrame:CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height)];
[self.photosViewController.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
}
completion:^(BOOL finished) {
if (finished) {
button.tag = 0;
}
}];
self.stepsView is an IBOutlet UIView and self.photosViewController.view is an child view controllers view that has been added to the view.
With the current code only the self.PhotosViewController.view animates. However if i comment out the line where i add the child view controllers view as a subview then the self.stepsView animates correctly.
Even if i add the child view controller and its view before this method is called the same error happens.
Need help as i ran in to this a couple of months back with another app and had to do a dirty hack to get around it and now want to solve this.
Thanks
In the section on view animation in the View Programming Guide there is a specific mention of how to animate subviews.
Basically, you should use transitionWithView:duration:options:animations:completion: rather than animateWithDuration:delay:options:animations:completion:.
The first view will not be visible, because its origin.y is beyond the height of the visible view. If it was not visible when the animation starts, you will of course see nothing.
The second view is changed to fill the screen. Again, what you see depends on its initial position.

Resources