UIsplitViewController can't pushViewController, only the master view or only detail view can pushViewController inside it's view. I wan't to push a new view int the current UIsplitViewController. The UIsplitViewController is in a UITabBarController.
How to solve it?
self.splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryHidden;
[MLTool pushView:self newView:USER_VIEW];
+(id)pushView:(UIViewController*)view newView:(NSString*)newView{
UIViewController *svc = [view.storyboard instantiateViewControllerWithIdentifier:newView];
//NSAssert(svc, #"pushView nil");
[view.navigationController pushViewController:svc animated:YES];
return svc;
}
- (void)viewWillAppear:(BOOL)animated{
SplitProductView* split=(SplitProductView* )self.splitViewController;
[split resetSplit: [[UIApplication sharedApplication] statusBarOrientation]];
//self.splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryOverlay
}
-(void)resetSplit :(UIInterfaceOrientation)toInterfaceOrientation {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
//TODOX:iphone
if (isPad)
{
if(UIInterfaceOrientationIsPortrait(toInterfaceOrientation)){
self.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryOverlay;
}
else{
//if (self.displayMode == UISplitViewControllerDisplayModePrimaryOverlay)
{//ios的bug,必须这三行,不然左边有黑边
// if (SYSTEM_VERSION_MORE_THAN(#"8.0"))
{
self.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryHidden;
self.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible;
self.preferredDisplayMode = UISplitViewControllerDisplayModeAutomatic;
}
}
}
}
}
}
Related
I'm trying to push a view controller from the appdelegate. Its redirecting to the proper view controller but the UI is missing.
Code
-(void)checkConditionToMoveToPaynoteDetailPage
{
if([_topViewController isKindOfClass:[TCSPayNoteHomeViewController class]])
{
[[NSNotificationCenter defaultCenter] postNotificationName:popCurrentPaynoteDetailPage object:self];
[self performSelector:#selector(moveToPaynoteDetailPage) withObject:nil afterDelay:2];
}
else{
BOOL ctrlIsPresent = NO;
for (id ctrlr in self.navigationCtrlArray ) //required controlled is in betwwen
{
if([ctrlr isKindOfClass:[TCSPayNoteHomeViewController class]])
{
ctrlIsPresent = YES;
}
}
if(ctrlIsPresent) //required controlled is in betwwen
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.navController popToViewController:[self.navigationCtrlArray objectAtIndex:0] animated:YES]; // top is required controller
[self performSelector:#selector(moveToPaynoteDetailPage) withObject:nil afterDelay:2];
});
}
else{
[self moveToPaynoteDetailPage];
// rquired controller is not in a stack
}
}
}
-(void)moveToPaynoteDetailPage
{
UIViewController *viewController = [self getTopViewController];
TCSPayNoteHomeViewController *paynoteDetailCtrl= [[TCSPayNoteHomeViewController alloc] init];
TCSPayNote *payNoteData = [[TCSPayNote alloc] init];
payNoteData.payNoteEntryID = [_notifInfo valueForKey:#"id"];
paynoteDetailCtrl.payNoteData = payNoteData;
[viewController.navigationController pushViewController:paynoteDetailCtrl animated:NO];
}
View controller
-(UIViewController*)getTopViewController
{
UINavigationController *navController = (UINavigationController *)self.window.rootViewController;
UIViewController *viewController = navController.topViewController;
return viewController;
}
-(void)getNavigationCtrlArray
{
self.navController = (UINavigationController *)self.window.rootViewController;
self.navigationCtrlArray = [self.navController viewControllers];
}
I'm trying to push a view controller from the appdelegate. Its redirecting to the proper page but UI's are not loading while pushing.
I do something similar somewhere but have a different function for getTopViewController. Here is my code.
// Find and return top view controller
+ ( UIViewController * ) topViewController
{
return [fmUiUtil topViewControllerFrom:UIApplication.sharedApplication.keyWindow.rootViewController];
}
// Given a starting point, find the best top view controller
+ ( UIViewController * ) topViewControllerFrom:( UIViewController * ) vc
{
if ( vc.presentedViewController )
{
return [fmUiUtil topViewControllerFrom:vc.presentedViewController];
}
else if ( [vc isKindOfClass:UISplitViewController.class] )
{
UISplitViewController * svc = ( UISplitViewController * ) vc;
if ( svc.viewControllers.count )
{
return [fmUiUtil topViewControllerFrom:svc.viewControllers.lastObject];
}
else
{
return vc;
}
}
else if ( [vc isKindOfClass:UINavigationController.class] )
{
UINavigationController * svc = ( UINavigationController * ) vc;
if ( svc.viewControllers.count )
{
return [fmUiUtil topViewControllerFrom:svc.topViewController];
}
else
{
return vc;
}
}
else if ( [vc isKindOfClass:UITabBarController.class] )
{
UITabBarController * svc = ( UITabBarController * ) vc;
if ( svc.viewControllers.count )
{
return [fmUiUtil topViewControllerFrom:svc.selectedViewController];
}
else
{
return vc;
}
}
else
{
return vc;
}
}
Also, in the delegate, I use [topVC presentViewController ... and not [topVC.navigationController pushVC as you do.
For playing Video I am using MPMoviePlayerController,my app supports only portrait mode but For playing Video I need to support Landscape too. Every thing is working fine till iOS 7.x. In iOS 8.0, After exiting Full screen there remains a navigation bar. Please refer below image.
In App delegate, under supportedInterfaceOrientationsForWindow, following is used.
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if (self.forceLandscapeRight) {
return UIInterfaceOrientationMaskAll;
}
return UIInterfaceOrientationMaskPortrait;
}
Noe in my controller class for initiating MPMoviePlayerController:
[self.mpMoviePlayerContr setContentURL:object];
[theMoviPlayer prepareToPlay];
self.mpMoviePlayerContr.controlStyle = MPMovieControlStyleEmbedded;
self.mpMoviePlayerContr.scalingMode = MPMovieScalingModeAspectFit;
[self.mpMoviePlayerContr play];
self.mpMoviePlayerContr.view.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
self.mpMoviePlayerContr.shouldAutoplay = YES;
[theMoviPlayer setFullscreen:false animated:YES];
Also, I have some notification for entering and exiting Full screen.
- (void) moviePlayerWillEnterFullscreenNotification:(NSNotification*)notification {
ED_APPDelegate.forceLandscapeRight = YES;
[self.mpMoviePlayerContr setFullscreen:YES animated:YES];
[self.mpMoviePlayerContr play];
}
- (void) moviePlayerWillExitFullscreenNotification:(NSNotification*)notification {
ED_APPDelegate.forceLandscapeRight = NO;
[self.mpMoviePlayerContr setFullscreen:NO animated:YES];
[self.mpMoviePlayerContr play];
}
- (void)orientationChanged:(NSNotification *)notification
{
UIDeviceOrientation currentOrientation = [[UIDevice currentDevice] orientation];
ED_APPDelegate.forceLandscapeRight = NO;
if (currentOrientation == UIDeviceOrientationLandscapeLeft ||currentOrientation == UIDeviceOrientationLandscapeRight ) {
[self.mpMoviePlayerContr setFullscreen:YES animated:YES];
[self.mpMoviePlayerContr play];
ED_APPDelegate.forceLandscapeRight = YES;
} else {
if (self.mpMoviePlayerContr.playbackState == MPMoviePlaybackStatePaused) {
[self.mpMoviePlayerContr play];
}
[self.mpMoviePlayerContr setFullscreen:NO animated:YES];
ED_APPDelegate.forceLandscapeRight = NO;
}
}
Above code is working fine in iOS 7.x, but have issue in iOS 8.0.
I can remove the toolbar but I am left width a blur of the height the toolbar was.
Any idea on how to remove this?
The code below is the function. It's pretty straight forward.
I use this in a webview using phonegap.
-(void) removeBar {
// Locate non-UIWindow.
UIWindow * keyboardWindow = nil;
for (UIWindow * testWindow in [
[UIApplication sharedApplication] windows]) {
if (![
[testWindow class] isEqual: [UIWindow class]
]) {
keyboardWindow = testWindow;
break;
}
}
// Locate UIWebFormView.
for (UIView * possibleFormView in [keyboardWindow subviews]) {
// iOS 5 sticks the UIWebFormView inside a UIPeripheralHostView.
if ([
[possibleFormView description] rangeOfString: #"UIPeripheralHostView"].location != NSNotFound) {
// remove the border above the toolbar in iOS 6
[
[possibleFormView layer] setMasksToBounds: YES];
for (UIView * subviewWhichIsPossibleFormView in [possibleFormView subviews]) {
if ([
[subviewWhichIsPossibleFormView description] rangeOfString: #"UIWebFormAccessory"].location != NSNotFound) {
[subviewWhichIsPossibleFormView removeFromSuperview];
// http://stackoverflow.com/questions/10746998/phonegap-completely-removing-the-black-bar-from-the-iphone-keyboard/10796550#10796550
UIScrollView * webScroll;
if ([
[
[UIDevice currentDevice] systemVersion] floatValue] >= 5.0) {
webScroll = [
[self webView] scrollView];
} else {
webScroll = [
[
[self webView] subviews] lastObject];
}
CGRect newFrame = [webScroll frame];
float accessoryHeight = [subviewWhichIsPossibleFormView frame].size.height;
newFrame.size.height += accessoryHeight;
[subviewWhichIsPossibleFormView removeFromSuperview];
[webScroll setFrame: newFrame];
}
}
}
}
}
If you hit this problem, make sure to head over to https://bugreport.apple.com and duplicate rdar://9844216
- (void)removeKeyboardTopBar {
// Locate non-UIWindow.
UIWindow *keyboardWindow = nil;
for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
if (![[testWindow class] isEqual:[UIWindow class]]) {
keyboardWindow = testWindow;
break;
}
}
// Locate UIWebFormView.
for (UIView *possibleFormView in [keyboardWindow subviews]) {
if ([[possibleFormView description] hasPrefix:#"<UIPeripheralHostView"]) {
for (UIView* peripheralView in possibleFormView.subviews) {
// HERE!! hides the backdrop (iOS 7)
if ([[peripheralView description] hasPrefix:#"<UIKBInputBackdropView"]) {
[[peripheralView layer] setOpacity:0.0];
}
// hides the accessory bar
if ([[peripheralView description] hasPrefix:#"<UIWebFormAccessory"]) {
// remove the extra scroll space for the form accessory bar
CGRect newFrame = diaryEditorView.scrollView.frame;
newFrame.size.height += peripheralView.frame.size.height;
diaryEditorView.scrollView.frame = newFrame;
// remove the form accessory bar
[peripheralView removeFromSuperview];
}
// hides the thin grey line used to adorn the bar (iOS 6)
if ([[peripheralView description] hasPrefix:#"<UIImageView"]) {
[[peripheralView layer] setOpacity:0.0];
}
}
}
}
}
User2038156's answer did not worked well for me on 7.1 because it also excludes the panel behind the keyboard, making it completely transparent. To remove only the background of the extra area you can use this code:
- (void)removeBar {
if(self.isHidingDoneBar){
UIWindow *keyboardWindow = nil;
for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
if (![[testWindow class] isEqual:[UIWindow class]]) {
keyboardWindow = testWindow;
break;
}
}
// Locate UIWebFormView.
for (UIView *possibleFormView in [keyboardWindow subviews]) {
if ([[possibleFormView description] hasPrefix:#"<UIPeripheralHostView"]) {
for (UIView* peripheralView in possibleFormView.subviews) {
// HERE!! hides the backdrop (iOS 7)
if ([[peripheralView description] hasPrefix:#"<UIKBInputBackdropView"] && peripheralView.frame.size.height == 44) {
[[peripheralView layer] setOpacity:0.0];
}
// hides the accessory bar
if ([[peripheralView description] hasPrefix:#"<UIWebFormAccessory"]) {
// remove the extra scroll space for the form accessory bar
CGRect newFrame = webView.scrollView.frame;
newFrame.size.height += peripheralView.frame.size.height;
webView.scrollView.frame = newFrame;
// remove the form accessory bar
[peripheralView removeFromSuperview];
}
// hides the thin grey line used to adorn the bar (iOS 6)
if ([[peripheralView description] hasPrefix:#"<UIImageView"]) {
[[peripheralView layer] setOpacity:0.0];
}
}
}
}
}
}
Here is a good quick way to accomplish the same in swift with only one line of code, done inside your custom UIResponder :
public override func becomeFirstResponder() -> Bool {
if !self.isEditing {
super.becomeFirstResponder()
//TODO: Do some sanity checks here , this is a hack to remove the backdrop on iOS 7.0 +
self.inputView?.superview?.subviews.first?.removeFromSuperview()
}
}
I want to stop bounce in webview. can my app get rejected in appstore if I use following statement in my code?
self.viewController.webView.scrollView.bounces = NO;
Thanks!
if ([[[UIDeice currentDevice] SystemVersion] floatValue] >= 5.0)//iOS>=5.0
{
webView.scrollView.bounces = NO;
}
else//iOS<5.0
{
for (id subview in webView.subviews)
{
if ([[subview class] isSubclassOfClass: [UIScrollView class]])
((UIScrollView *)subview).bounces = NO;
}
}
if (webView respondsToSelector:#selector(scrollView)]) {
webView.scrollView.bounces = NO;
} else {
for (id subview in webView.subviews) {
if ([[subview class] isSubclassOfClass:[UIScrollView class]]) {
((UIScrollView*)subview).bounces = NO;
}
}
}
i have use a UIWebview in IOS 5. I try to set contenteditable="true" to make uiwebview editable.
The screenshoot of my app is similar to an image in this link How do you remove the Next and Prev buttons from virtual keyboard in Sencha Touch / Phonegap application,
my problem is i want to remove this prev & next button from the keyboard, but i dont know how. Can some body help me?
thank you
This is an old answer and is no longer working on iOS 9. For an updated solution, see my answer here.
It is a gray-area, but certainly possible.
See here: http://ios-blog.co.uk/iphone-development-tutorials/rich-text-editing-a-simple-start-part-1/
Register for notification on keyboard showing:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
Then:
- (void)keyboardWillShow:(NSNotification *)note {
[self performSelector:#selector(removeBar) withObject:nil afterDelay:0];
}
- (void)removeBar {
// Locate non-UIWindow.
UIWindow *keyboardWindow = nil;
for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
if (![[testWindow class] isEqual:[UIWindow class]]) {
keyboardWindow = testWindow;
break;
}
}
// Locate UIWebFormView.
for (UIView *possibleFormView in [keyboardWindow subviews]) {
// iOS 5 sticks the UIWebFormView inside a UIPeripheralHostView.
if ([[possibleFormView description] rangeOfString:#"UIPeripheralHostView"].location != NSNotFound) {
for (UIView *subviewWhichIsPossibleFormView in [possibleFormView subviews]) {
if ([[subviewWhichIsPossibleFormView description] rangeOfString:#"UIWebFormAccessory"].location != NSNotFound) {
[subviewWhichIsPossibleFormView removeFromSuperview];
}
}
}
}
}
Remove the empty area.
- (void)removeBar {
// Locate non-UIWindow.
UIWindow *keyboardWindow = nil;
for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
if (![[testWindow class] isEqual:[UIWindow class]]) {
keyboardWindow = testWindow;
break;
}
}
// Locate UIWebFormView
for (UIView *possibleFormView in [keyboardWindow subviews]) {
if ([[possibleFormView description] hasPrefix:#"<UIPeripheralHostView"]) {
for (UIView* peripheralView in [possibleFormView subviews]) {
// hides the backdrop (iOS 7)
if ([[peripheralView description] hasPrefix:#"<UIKBInputBackdropView"]) {
//skip the keyboard background....hide only the toolbar background
if ([peripheralView frame].origin.y == 0){
[[peripheralView layer] setOpacity:0.0];
}
}
// hides the accessory bar
if ([[peripheralView description] hasPrefix:#"<UIWebFormAccessory"]) {
// remove the extra scroll space for the form accessory bar
UIScrollView *webScroll;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0) {
webScroll = [[self webView] scrollView];
} else {
webScroll = [[[self webView] subviews] lastObject];
}
CGRect newFrame = webScroll.frame;
newFrame.size.height += peripheralView.frame.size.height;
webScroll.frame = newFrame;
// remove the form accessory bar
[peripheralView removeFromSuperview];
}
// hides the thin grey line used to adorn the bar (iOS 6)
if ([[peripheralView description] hasPrefix:#"<UIImageView"]) {
[[peripheralView layer] setOpacity:0.0];
}
}
}
}
}
It's the inputAccessoryView for UIWebBrowserView (inner UIWebView), you can hack it.
Here is an example: https://gist.github.com/bjhomer/2048571
I found the solution for iOS 8. You can check it here:
-(void) removeKeyboard {
UIWindow *keyboardWindow = nil;
for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
if (![[testWindow class] isEqual : [UIWindow class]]) {
keyboardWindow = testWindow;
break;
}
}
// Locate UIWebFormView.
for (UIView *possibleFormView in [keyboardWindow subviews]) {
if ([[possibleFormView description] hasPrefix : #"<UIInputSetContainerView"]) {
for (UIView* peripheralView in possibleFormView.subviews) {
for (UIView* peripheralView_sub in peripheralView.subviews) {
// hides the backdrop (iOS 8)
if ([[peripheralView_sub description] hasPrefix : #"<UIKBInputBackdropView"] && peripheralView_sub.frame.size.height == 44) {
[[peripheralView_sub layer] setOpacity : 0.0];
}
// hides the accessory bar
if ([[peripheralView_sub description] hasPrefix : #"<UIWebFormAccessory"]) {
for (UIView* UIInputViewContent_sub in peripheralView_sub.subviews) {
CGRect frame1 = UIInputViewContent_sub.frame;
frame1.size.height = 0;
peripheralView_sub.frame = frame1;
UIInputViewContent_sub.frame = frame1;
[[peripheralView_sub layer] setOpacity : 0.0];
}
CGRect viewBounds = peripheralView_sub.frame;
viewBounds.size.height = 0;
peripheralView_sub.frame = viewBounds;
}
}
}
}
}
}
You may try and improve this. try call this function inside Your UIKeyboardDidShowNotification event handler.
Hope this helps...
This is the level of views in accessory:
(UIWebFormAccessory) -> (UIToolbar) -> (UIImageView,UIToolbarButton,UIToolbarButton)