Screen move from bottom to top issue - ios

I want to show the screen from Top To Bottom but When I use HCYouTubeParser In my app, when i click on Done Button then screen move from bottom to top.I can not find the coding of Done Button How can it is possible?

HCYouTubeParser, this library using default MPMoviePlayerController class of MediaPlayer Framework which is provided by apple.
see this is the code inside HCYouTubeParser->ViewController.m
- (void)playVideo:(id)sender {
if (_urlToLoad) {
MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:_urlToLoad];
[self presentViewController:mp animated:YES completion:NULL];
}
}
So "Done" button is part of that controller. You have to override that "Done" button functionality by adding observer.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(doneButtonClick:)
name:MPMoviePlayerWillExitFullscreenNotification
object:nil];
-(void)doneButtonClick:(NSNotification*)aNotification{
NSNumber *reason = [notification.userInfo objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];
if ([reason intValue] == MPMovieFinishReasonUserExited) {
// Your done button action here
}
}
Refer this link :Done button event MPMoviePlayerController

First of all, the library you are using is presenting the view controller and by "default" iOS will do presenting from bottom to top. And you cannot find the code which makes the bottom to top.
Second if you want to change this bottom to top you can do the following to change it.
Make a custom transaction
Add the view controller as a child view controller and animate it from top to bottom or any other way you like.

Related

How to dismiss multiple view controllers which have been presented not pushed?

Scenario:
I need to show 3 or more popups one after the other on button click in each popup. I have created a different viewcontroller and xib files for each popup. So for displaying each popup I have used presentViewController instead of pushViewController.
That is, I have used this:
[self presentPopupViewController:searchPopUpView animationType:0];
instead of
[self.navigationController pushViewController:searchPopUpView animated:YES];
For dismissing a popup, the following code has been written:
[self dismissPopupViewControllerWithanimationType:0];
Issue:
The popups are displaying perfectly, but the background gets darker and darker whenever a popup shows up. After all popups have been dismissed I have to finally click on the blank screen to remove those darker parts. How to overcome this issue?
I think you are using MJPopupViewController to show pop-up.
If it is so, Then try this.
Suppose there is a controllerA from which you want to show a pop-up controller popupControllerB.
Then in your controllerA add Notifications Observer
Code to write in controllerA :
// Add Notification Observer when your view initialise.
[[NSNotificationCenter defaultCenter]addObserver:self selector:#selector(dismissPopup) name:#"DISMISS_POPUP" object:nil];
In viewWillDisappear remove the notifications observer
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
This method will be called when you Post-notification from your popupControllerB
-(void)dismissPopup {
[self dismissPopupViewControllerWithanimationType:MJPopupViewAnimationFade];
}
And In popupControllerB, Where you want to dismiss the Pop-up, write this code.
[[NSNotificationCenter defaultCenter] postNotificationName:#"DISMISS_POPUP" object:nil];
Above line of code will call a method written in your controllerA and dismiss the pop-up properly.
If you want to dismiss presented UIViewControllers you can use this code. I have used this approach to dismiss presentedViewControllers. It will dismiss all your presentedViewControllers on your rootViewController.
UIViewController* presVC = self.window.rootViewController;
while (presVC) {
UIViewController* temp = vc.presentingViewController;
if (!temp.presentedViewController) {
[vc dismissViewControllerAnimated:NO completion:^{}];
break;
}
vc = temp;
}

Issue in calling UIViewController view as subview in UIView

I am implementing MDSpreadView, a third party controller, in one of my projects. I have simply included every file related to it including xib. Calling it as subview.
The hierarchy of calling views is like this: there is a uiviewcontroller in which I am adding UIView as subview, and from that subview I am calling uiviewcontroller as subview.
MDViewController *MDvc = [[MDViewController alloc]initWithNibName:#"MDViewController_iPhone" bundle:nil ];
[self addSubview:MDvc.view];
It Appears fine but when I touch to scroll or select or for anything, Thread 1:EXC_BAD_ACCESS error occurs at selection delegate. Whereas delegates are implemented as it is in demo proj.
here is the image
I know there is some issue in calling subviews. How do I solve this?
The idea of taking a view out of one controller and inserting it as a subview in a different controller is a common cause of crashes. If you have to do it, make sure that the original controller (MDViewController in this case) is not released. You can do that by making it a strong property of the object that is hijacking its view or, better, look at the documentation for how to implement a container controller.
Finally get to know how to handle multiple views, especially when you have subviews and viewcontroller. Solution is very simple , in such situations you need to have delegates or there is a great thing which apple gives itself is NSNotification. I did solve my problem through NSNotification. On the button press(from where i have to call other view) i post a notification like this:
[[NSNotificationCenter defaultCenter] postNotificationName:#"WhatEverYouWantTocallIt" object:nil];
and i added observer in the class which i needed to call, like this:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(bringSpreadViewToFront) name:#"WhatEverYouWantTocallIt" object:nil];
AND added a selector, in selector u should handle it according to scenario you have i did this:
-(void)bringSpreadViewToFront{
NSArray *viewsToRemove = [self.view subviews];
for (UIView *v in viewsToRemove) {
[v removeFromSuperview];
}
MDViewController *md = [[MDViewController alloc] initWithNibName:#"MDViewController_iPhone" bundle:nil];
[self presentViewController:md animated:YES completion:nil];
}
i first removed the subviews one by one and then present my view controller, presenting pushing its your choice. it works perfect.. Cheers :)
Thank you Phillip for pushing me in a direction close to the solution.

hide custom tabbar when push

I have a customized tabbar in my app. I want to hide my tabbar when pushing another viewcontroller.
Currently I implemented as this(The original tabbar has been hidden):
myViewController.hidesBottomBarWhenPushed = YES;
((CustomTabBarController *)self.tabBarController).customTabBar.hidden = YES;
[self.navigationController pushViewController:lookBookViewController animated:YES];
But when it is being pushed, it hides my customTabBar immediately. So you can see a black bottom bar in first viewcontroller. Is there a way to fix this problem?
Thanks.
put your these code in - (void)viewDidDisappear:(BOOL)animated;
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
myViewController.hidesBottomBarWhenPushed = YES;
((CustomTabBarController *)self.tabBarController).customTabBar.hidden = YES;
}
you can design like this
and then you need not to hide the tabbar , if you want to hide it , you can use my above code , I think if you design like this , the hide effect will be you want

Pressing on "Done" button while playing a YouTube video dismisses the rootViewController

I have UINavigationController which needs to be displayed right after my root UINavigationController using storyBoard segue.
[self performSegueWithIdentifier:#"LoginViewController" sender:self];
This storyBoard segue is Modal.
On top of this LoginViewController I embedded YouTube video using the snippet here.
While the video is playing, pressing on the "Done" button will cause my LoginViewController to be dismissed along with the video.
It also happens when the video ends.
Is there any way to handle the "Done" button? is there any notification which Let me know when the video ends?
Thanks in advance
Add the UITextfield Delegate to your class, then set the delegate property of your uitextfield to "self".
Handle the "done" (aka "return") key with the following method:
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
[textField resignFirstResponder];
return NO;
}
I found a notification which helped me to know when the video end but you will have to use it carefully.
Apparently, When the youTube video plays, it appears on top of the UIWindow, So just before you trigger your video register the UIWindowDidBecomeVisibleNotification notification. Like this:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(windowNowVisible:)
name:UIWindowDidBecomeVisibleNotification
object:self.view.window
];
When the video ends, The UIWindow comes visible again and and there you should remove the notification.

UIPopoverController not moving to original position after keyboard slides back down

I'm displaying a popover in iPad with a UINavigation bar. On the second view, I have a UISearchController that can display a keyboard. The keyboard pushes the popover up, which is fine, however if I now push the 'back' button on the UINavigation bar it dismisses the keyboard which is fine, but the popover doesn't slide back down to its original position. Anyone know how to fix that? Thanks!
Ok so I actually figured out (I believe) what your question was asking...and just in case anyone stumbles upon this from google, I figured I'd answer how I did it. It feels like a hack job but I haven't been able to find any other way to do it.
In the controller that brings up the keyboard,I had it post a notification whenever the keyboard dismisses:
[aTextField resignFirstResponder];
[[NSNotificationCenter defaultCenter] postNotificationName:#"movePopups" object:nil];
Then back on my home screen controller, that controls the UIPopover, I added a listener:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(movePopUpToRightLocation)
name:#"movePopups"
object:nil];
inside the init. Be sure to remember to remove the listener in your dealloc for good programming practice:
[[NSNotificationCenter defaultCenter] removeObserver:self];
So then whenever I get notification that the keyboard disappears, I get a reference to the button that the popover shows up from, and just have it re-appear directly from it:
-(void)movePopUpToRightLocation {
NSLog(#"move pop up to right location");
if (morePopUp) {
UIBarButtonItem *barButtonItem = (UIBarButtonItem *)[[bottomToolBar items] objectAtIndex:0];
[morePopUp presentPopoverFromBarButtonItem:barButtonItem
permittedArrowDirections:UIPopoverArrowDirectionDown
animated:YES];
}
}
I haven't added any checks for which popup it is, but I can easily do that if I have more than 1 type of popover / button that it would appear from. But that's the basic premise that you can go from.
Hope it helps!
You could also register for the UIKeyboardDidHideNotification somewhere in the initializer.
[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(movePopoverBack:) name:UIKeyboardDidHideNotification object:nil];
This code moves the popover back:
- (void)movePopoverBack:(id)sender {
if ([self.settingsPopoverController isPopoverVisible]) {
[self performSelector:#selector(hidePopover) withObject:nil afterDelay:0.1];
[self performSelector:#selector(movePopoverBack) withObject:nil afterDelay:0.5];
}
}
- (void)hidePopover {
[self.settingsPopoverController dismissPopoverAnimated:YES];
}
- (void)movePopoverBack {
[self.settingsPopoverController
presentPopoverFromBarButtonItem:self.bottomToolbar.settingsButton
permittedArrowDirections:UIPopoverArrowDirectionDown
animated:YES];
}
I didn't get it working without the delays, but this seems to be acceptable for my current project. Hope it helps someone.
After you press the Back button you should manually call resignFirstResponder for the search field (for example inside viewDidDisappear).
This should help, but the issue still will be reproduced under iOS 4 when the device is in Landscape orientation with Hthe ome button on the left side

Resources