How Is This Slide-Up Menu from the iPhone Messages App Implemented

How is this slide-up menu from the iPhone messages app implemented?

It's called a UIActivityViewController. You can read more about it here:

http://nshipster.com/uiactivityviewcontroller/

iOS Slide up menu

Steps up to 5 contain the creation of the subview itself, but if you are only interested on the dragging events read from step five, which is about the panGestureRecognizer.

  1. Create a custom UIView, I have also created a delegate protocol to inform the viewController when an action occurs on the subview. Depending on how much complicated your subview will be, you may want to create a xib file with the same name for that. Let's call it filterView from now on.

  2. Create two methods like "hide" and "show" on the filterView. If you do not want to have a button (namely the small button with the arrow, I ll call it dropdownButton) to close and open the filterView, you may skip this step, but I strongly recommend to implement them. What you have to do is to animate filterView.frame.origin.y to

    • [[UIScreen mainScreen] bounds].size.height - dropDownButton.frame.height to hide the filterView

    • [[UIScreen mainScreen] bounds].size.height - filterView.frame.size.height to show it.

If requested I can also send code for that animations.

3.
Open the xib file for the UIViewController and add a UIView, so that only its dropdown button will be visible. Click the view and change its class to filterView using the rightmost pane in the interface builder. At this step you should be able to see your filtersView's tip on the bottom of the page if you did everything correctly. If not, the filterView.xib file is probably not correctly connected to filterView source code files.

4
.
Import the FilterView in the ViewController and connect as IBOutlet & synthetize it. Implement the delegate protocol if you have written one. If you have buttons on the filterView, you will need it later on. The delegate protocol should include optional messages like

-(void) featuresButtonTappedOnFilterView: (FilterView *) filterView;

and in the implementation you should do what you have to do in the viewController, like opening another viewController.

5
. On the viewControllers xib file create a panGestureRecognizer and add it to your filterView. PanGestureRecognizer is a gestureRecognizer which will handle the dragging events. At first the whole filterView will be able to dragged around by clicking any point on it, we will get to that later. Connect the gestureRecognizer as IBOutlet and create an IBAction (preferably with a better name) like:

-(IBAction)_panRecogPanned:(id)sender;

In the viewDidLoad method of the ViewController dont forget to set the delegate as:

[_panRecog setDelegate:self];

6
. Implement other states for more power. but stateChanged will be sufficient at first.

- (IBAction)_panRecogPanned:(id)sender {

switch ([(UIPanGestureRecognizer*)sender state]) {

case UIGestureRecognizerStateBegan: { } break;
case UIGestureRecognizerStateChanged: {

if ( [((UIPanGestureRecognizer *)sender) locationInView:_filterView].y > dropDownButton.frame.height )
return; // Only drag if the user's finger is on the button

CGPoint translation = [_panRecog translationInView:filterView];

//Note that we are omitting translation.x, otherwise the filterView will be able to move horizontally as well. Also note that that MIN and MAX were written for a subview which slides down from the top, they wont work on your subview.
CGRect newFrame = _panRecog.view.frame;
//newFrame.origin.y = MIN (_panRecog.view.frame.origin.y + translation.y, FILTER_OPEN_ORIGIN_Y);
//newFrame.origin.y = MAX (newFrame.origin.y, FILTER_INITIAL_ORIGIN_Y);
newFrame.origin.y = _panRecog.view.frame.origin.y + translation.y;
_panRecog.view.frame = newFrame;

[_panRecog setTranslation:CGPointMake(0, 0) inView:self.view];

} break;

//Remember the optional step number 2? We will use hide/ show methods now:
case UIGestureRecognizerStateEnded:
case UIGestureRecognizerStateCancelled: {

//CGPoint velocity = [_panRecog velocityInView:_panRecog.view];
//Bonus points for using velocity when deciding what to do when if the user lifts his finger

BOOL open;

/*
if (velocity.y < -600.0) {
open = NO;
}

else if (velocity.y >= 600.0) {
open = YES;
} else
*/

if ( _panRecog.view.frame.origin.y > (FILTER_OPEN_ORIGIN_Y + FILTER_INITIAL_ORIGIN_Y) / 2 ) {
open = YES;
}

else {
open = NO;
}

if (open == YES) {

[_filterView show];
}

else {
[_filterView hide];

}

} break;

default:
break;
}

}

Note: My filter view was on the top of the page instead of the bottom, as it is the subview will move out of the page borders. Comment out the MAX and MIN statements to fix that, I am to lazy to write them by myself. The code is modified after copy&paste, it may (and probably will) contain typos.

Can't seem to achieve the same effect on my slide menu as Any.Do

There is no need to get rid of your storyboard to recreate this, that's what IBOutlets are for. Any way, it looks like this was made by creating a UIScrollView that takes up the entire screen. Then add a UITableView to the upper section of the scroll view. Mind you in order for this to work, you'll need to disable scrolling on the scroll view in the background.

From there you can programmatically add the other elements to the scroll view to be rendered off screen, since there are only three they can probably just be buttons. And finally, since scrolling is disabled on the background scroll view you can add an image with a UISwipeGestureRecognizer at the bottom of the screen to manually change the scroll view's content offset property.

Is this native to iOS?

Yes this is native iOS Popup and called UIActivityViewController, for more details you can refer to below links...

https://developer.apple.com/reference/uikit/uiactivityviewcontroller
http://nshipster.com/uiactivityviewcontroller/

iPhone dev: Creating sliding drawers like Path and Facebook apps

Try These from Cocoa Controls:

JTRevealSidebar http://cocoacontrols.com/platforms/ios/controls/jtrevealsidebar

clcascade http://cocoacontrols.com/platforms/ios/controls/clcascade

StackScrollView http://cocoacontrols.com/platforms/ios/controls/stackscrollview

Many more on the same site like:
http://cocoacontrols.com/platforms/ios/controls/mfslidingnavigationcontroller
http://cocoacontrols.com/platforms/ios/controls/psstackedview

How to define a custom keyPad in my App?

  1. Why are you declaring the custom keyboard in the UITabBarController class ? You can declare it in the view controller that is attached to that particular tabBarItem. If you add it to the that view controller, I am sure you can just make it resignFirstResponder or removeFromSuperView and manipulate it as you want.

  2. Or you can just create a separate class for your customKeyboard, and add it along with your other classes. Simply include that class and create objects in other view controllers to manipulate them, and then release them. This is very easy and it is better programming compared to your approach, as at a later point of time, if you need to make changes or release 2.0 version of your app, it will come in handy and save some development time !



Related Topics



Leave a reply



Submit