How to enable full screen Pan back for UINavigationController - ios

From iOS7 apple provide a way to pan back UINavigationController, but it can only be done by swipe form the edge of the screen. How to enable full screen pan back gesture?

I really spend a lot of time trying to solve this problem, at last I found the way. I just ask a question and answer it myself to share the solution here.
Pls refer my blog to get more detail enter link description here
Demo code:
#import "TestNavigationController.h"
#interface _UINavigationInteractiveTransition
#end
#interface UINavigationController(Custom)
#property (strong, nonatomic) _UINavigationInteractiveTransition * _cachedInteractionController;
#end
#implementation TestNavigationController
{
UIPanGestureRecognizer *_p;
}
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(#"%#", self.interactivePopGestureRecognizer
);
_p = [[UIPanGestureRecognizer alloc]initWithTarget:self._cachedInteractionController action:#selector(handleNavigationTransition:)];
NSLog(#"%#", self._cachedInteractionController);
[self.view addGestureRecognizer:_p];
}
#end
EDIT NOTE:
This exposes Private APIs.

Related

When adding UIView instantiated with an .xib to the Storyboard buttons don't work and background color can't be changed

I am working on an iOS project and wanted to include a UIView that is reused on multiple screens in the application (appearing at the bottom of different UIViews). I am using a storyboard for the UI work so far but created an .xib file to be used by the reusable view (playerView in code below).
The view gets added but the button I have added to the View is unresponsive, also my background color cannot be changed on the view. I have tried to set background color programmatically and in the .xib with no luck. Very weird symptoms and I tried to instantiate the view from #5 of this article and probably did something wrong. I dont fully understand everything in the article which makes me nervous - for instance my showSubclassedView method returns IBAction but I just call the function name in code and dont use a button (I did hook up the buttons in the view as the article described though).
Here is the code:
EventViewController.m (where I trry and add PlayerView)
#import "EventViewController.h"
#import "PlayerView.h"
#interface EventViewController ()
-(IBAction)showSubclassedView;
#end
#implementation EventViewController
-(IBAction)showSubclassedView
{
[PlayerView presentInViewController:self];
}
PlayerView.h (.h for reusable view)
#import <UIKit/UIKit.h>
#import "Utils.h"
#class PlayerView;
#protocol PlayerViewDelegate
-(void)playerViewTouchedUp:(PlayerView*) playerView;
-(void)playerViewDidDismiss:(PlayerView*) playerView;
#end
#interface PlayerView : UIView
+(void)presentInViewController:(UIViewController<PlayerViewDelegate>*) playerView;
-(IBAction)viewTouchedUp;
-(IBAction)dismiss;
#end
PlayerView.m (.m for reusable view)
#import "PlayerView.h"
#interface PlayerViewOwner : NSObject
#property(nonatomic,weak) IBOutlet PlayerView *playerView;
#end
#implementation PlayerViewOwner
#end
#interface PlayerView ()
#property (nonatomic, weak) UIViewController <PlayerViewDelegate> *delegateViewController;
#end
#implementation PlayerView
+(void)presentInViewController:(UIViewController<PlayerViewDelegate> *)viewController
{
PlayerViewOwner *owner = [PlayerViewOwner new];
[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:owner options:nil];
owner.playerView.delegateViewController = viewController;
[viewController.view addSubview:owner.playerView];
}
-(IBAction)viewTouchedUp
{
//forward to delegate
NSLog(#"you clicked a button");
[self.delegateViewController playerViewTouchedUp:self];
}
-(IBAction)dismiss
{
[self removeFromSuperview];
// Forward to delegate
[self.delegateViewController playerViewDidDismiss:self];
}
#end
PlayerView.xib has a UIbutton on it that connects it to viewTouchedUp method in PLayerView.m
Is there anything I did wrong in the code above? Is this the best way to do a reusable view to display on other views?
Thank you!
Here's a workaround I found after not being able to solve this.
New implementation is from this article
I reverted my changes from my initial question and implemented this. It lacks the nice protocol separation for talking back and forth and I might need something like this later but I think now I can still implement a protocol to solve this.
At least with this solution I have usable items in my view and a background that changes!

Storyboard, drag link to an IBAction from a container view to the parent

Here's a trivial VC called Club
Club has a function:
#implementation Club
-(IBAction)clickMe
{
NSLog(#"Whoa!");
}
#end
Now regarding ButtonA. Obviously in Storyboard you can drag from ButtonA to the function "clickMe" in "Club".
Now. Regarding ButtonB.
Is there any way, in Storyboard, to drag from ButtonB, to "clickMe" in "Club"?
Perhaps using the mysterious "object" objects, or ... ??
Note that, obviously, you can make a class for the small view, and have a function:
#implementation SmallViewOnRight
-(IBAction)sameAsClickMe
{
[(Club*)self.parentViewController clickMe];
}
#end
Then, you can drag from ButtonB to sameAsClickMe. But that's a complete nuisance.
Note that it's very normal to use container views like this, to handle different "areas" of your main view (particularly if you have stuff sliding around and so on, and when you have many things "on top of each other"). It's hugely convenient to move "sections" outside the main view, using container views. But it's a complete nuisance "passing up" the clicks.
Is there an obscure way to do this in Storyboard? Cheers!
Just FTR, iOS7+ only, nothing older
Note - going in the "other direction" is well-explored and easy enough to do.
No, you can't do that but you can use delegates for this behavior.
In SecondViewController.h:
#protocol SecondViewControllerDelegate <NSObject>
-(void)clickMe;
#end
#interface SecondViewController.h: UIViewController
#property (weak, nonatomic) id <SecondViewControllerDelegate> delegate;
#end
In SecondViewController.m:
#implementation SecondViewController
- (IBAction) buttonBClicked:(id)sender {
if ([self.delegate respondsToSelector:#selector(clickMe)] {
[self.delegate performSelector:#selector(clickMe)];
}
}
#end
In ClubViewController.m:
#import "SecondViewController.h"
#interface ClubViewController () <SecondViewControllerDelegate>
#end
#implementation ClubViewController.m
// make yourself a delegate of SecondViewController somewhere in your code. For example, in prepareForSegue.
-(void)clickMe {
NSLog (#"Clicked");
}
#end
EDIT:
Try with Unwind Segues!
I've posted an answer here on how to use them. But skip step 4.

ScrollView Page swipe

I have a ScrollView in which there are 10 viewControllers I have added each ViewController and it contaning two button Yes and No Button. Yes Button take you to the next screen or ViewController.
My page is swiping well but whenever i perform an action through yes button , i am able to go to the next screen but my page swipe is not working anymore.
what i wanted is that if yes button action is performed then swipe of page is done in correct way?
#interface PagerViewController : UIViewController <UIScrollViewDelegate>
#property (nonatomic, strong) IBOutlet UIScrollView *scrollView;
#property (nonatomic, strong) IBOutlet UIPageControl *pageControl;
-(IBAction)changePage:(id)sender;
- (void)previousPage;
- (void)nextPage;
I don't know what you have done inside changePage: but if you have done something like this, then your scrollview page swipe should work fine.
- (void)gotoPage
{
NSInteger page = // page you want to go to;
// update the scroll view to the appropriate page
CGRect bounds = self.scrollView.bounds;
bounds.origin.x = CGRectGetWidth(bounds) * page;
bounds.origin.y = 0;
[self.scrollView scrollRectToVisible:bounds animated:NO];
}
You can call above function inside your changePage: method.
I'm not sure but I wish It could help you,See here, You should use UIPageViewControleller which has been provided by Apple. Here Check out Apple Docs. Happy Coding!

How to improve the movement of an image within my ios App

Within my ios App I need to move an image but I am encountering some problems. I am able to move the image correctly to the calculated coordinates, but I need to click on the button that initiates the movement twice before it will appear in the right position, os on the first click the image will only show at the initial position without relocating to the new position.
This is my code:
(EDITED)
Viewcontroller.m
#import "ndpViewController.h"
#interface ndpViewController ()
#end
#implementation ndpViewController
#synthesize image;
-(void)viewDidLoad
{
}
-(void)dealloc
{
}
- (IBAction)calculatePush:(id)sender {
image.hidden=NO;
image.center=CGPointMake(376, 927);
}
- (void)viewDidUnload {
}
#end
Viewcontroller.h
#import <UIKit/UIKit.h>
#interface ndpViewController : UIViewController
{
IBOutlet UIImageView *image;
}
#property (weak, nonatomic) IBOutlet UIButton *calculate;
#property (nonatomic,retain) UIImageView *image;
#end
Any idea why I need to click twice before the image will relocate?. I don't need any kind of animation, just a little image (representing a cross) that will show at a specific point on top of a graphic.
Thank you very much and regards.
I dont exactly understand some of the code. But I think I understood your question which is 'How do I do something first click, and then something else on the second click?'
bool isFirstClick = true;
-(IBAction)CLickEvent:(id)sender{
if(isFirstClick){
//enter first click action here
isFirstClick = false;
}else{
//enter second click action here
isFirstClick = true;
}
}
You have not posted enough code to know for sure. But let me try it this way. What happens if zfw <= 26308 ?? It appears nothing. So in that case nothing moves. How does it EVER move when zfw is <= 26308?
NOTE:
Ok... the code as you have NOW posted it will NEVER relocate because you are always setting the position of the image to the same position on every click.
Actually the problem is even more weird than I thought. The image moves at first click if I type text into any text box within the app, but it will only move at the second click if I type in numbers at the any of those text boxes.
Any suggestion????

Handling touches within UIScrollview

I have a view that contains a UIScrollView. The UIScrollView contains an UIImageView (only one for now but there will be more latter). I want to be able to drag the UIImageView out of the UIScrollView and into the superview.
I have reviewed every similar question and example I can find online and still cant get my head around how this works.
At first I couldn't get touches to register all whithin the scrollview. After a lot of searching I have found a way to get touchesbegan to register as follows:
First I created a new view based project and in the auto-created "ViewController.h"
I created an IBOutlet named slider.
Then in the auto-created "ViewController.m" I created the UIScrollview.
In IB I added a UIScrollView to the storyboard then connected it to the "slider" IBOutlet.
Next I added class file to the projects. This new class is a subclass os UIImageView. I named this class "DragableImage" In the
Then in IB I dropped an image into the UIScrollview clicked on it and changed the class to "DragableImage"
In the DragableImage.m I voided touches began and simply told it to become hidden if clicked.
This works and the touch registers and makes the image disappear but how do I now add the new image to the main view and have it follow my finger?
This is what I have in the way of code:
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController {
IBOutlet UIScrollView *slider;
}
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[slider setScrollEnabled:YES];
[slider setContentSize:CGSizeMake(306, 1560)];
[slider setShowsVerticalScrollIndicator:NO];
slider.canCancelContentTouches = NO;
slider.delaysContentTouches = NO;
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
#end
DragableImage.h
#import <UIKit/UIKit.h>
#interface DragableImage : UIImageView
#end
DragableImage.m
#implementation DragableImage
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
self.hidden = YES;
}
#end
How to make this work?
There is one obvious problem that can arise here. Namely, how to tell the difference between dragging to scroll and dragging an image. The way I would handle this is to setup a tap and hold gesture recognizer (http://developer.apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/GestureRecognizers/GestureRecognizers.html).
Once you detect a hold you could set it up so that further touches/gestures get routed to you drag and drop code. You can find a nice tutorial for that here:
http://www.ancientprogramming.com/2012/04/05/drag-and-drop-between-multiple-uiviews-in-ios/

Resources