Hi I am trying to remove the UIWebFormAccesory that appears on top of the keyboard on iOS when entering text to a WKWebView text field. I have a slight hack below based on previous answers to this question, but they are all outdated and no longer work. I've added a picture below, with a red box around the bar I'm talking about:
The code below works if I run it 2x in a row, but then causes weird behavior on the keyboard, which eventually crashes the application.
for (UIWindow* wind in [[UIApplication sharedApplication] windows]) {
for (UIView* currView in wind.subviews) {
if ([[currView description] containsString:#"UIInputSetContainerView"]) {
for (UIView* perView in currView.subviews) {
for (UIView *subView in perView.subviews) {
if ([[subView description] containsString:#"UIWebFormAccessory"]) {
[subView setHidden:true];
[subView removeFromSuperview];
// CGRect f = perView.frame;
// CGRect n = CGRectMake(0, f.origin.y, f.size.width, f.size.height-44.0);
// [perView setFrame:n];
}
}
}
}
}
}
Was wondering if anyone has had any luck with this? I'm using Objective-C but a swift solution would be fine as well, thanks for the help!
Also here are the older threads that I have looked at, but haven't had any luck with:
How to find UIWebView toolbar (to replace them) on iOS 6?
Remove form assistant from keyboard in iPhone standalone web app
Related
The title says it all! but to be more clear, please check this screenshot. This is a 360 video playback using the Google VR https://developers.google.com/vr/ios/ but I want to know if it is possible to remove this little (info) button? and instead overlay our own set of video controlers?
Google allow you to create a custom GVRView which doesn't have the (i) icon - but it involves creating your own OpenGL code for viewing the video.
A hack working on v0.9.0 is to find an instance of QTMButton:
let videoView = GVRVideoView(frame: self.view.bounds)
for subview in self.videoView.subviews {
let className = String(subview.dynamicType)
if className == "QTMButton" {
subview.hidden = true
}
}
It is a hack though so it might have unintended consequences and might not work in past or future versions.
Well, I have an answer to my own question. Alright, the (i) button cannot be removed. at leased not for now. check this answer
Hi. The (i) is intentional and designed to let users and other
developers understand the feature. It links to a Google help center
article. We do not currently allow developers to disable it.
https://github.com/googlevr/gvr-ios-sdk/issues/9#issuecomment-208993643
GVRVideoView *videoView = [[GVRVideoView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height)];
for (UIView *view in videoView.subviews) {
if ([view isKindOfClass:[UIButton class]] ) {
if ([NSStringFromClass([view class]) isEqualToString:#"QTMButton"] ) {
[view removeFromSuperview];
}
}
}
I need to implement a dismissive keyboard (swiping down to dismiss) like the one in the stock messages app on iOS.
I have this code to get the keyboard view:
func keyboardWillShowWithNotification(notification:NSNotification) {
let keyboardView = accessoryView.superview
}
And I connected the UIPanGestureRecognizer of the tableView to detect when I need to start moving the keyboard down.
func handleTableViewPan(gr:UIPanGestureRecognizer) {
let location = panGestureRecognizer.locationInView(self.view)
let offset = ... //calculated correctly
keyboardView.frame.origin.y = originalKeyboardFrame.origin.y + offset
}
The method worked fine with iOS 8 but with iOS 9 it seems like the keyboard is hold in place a little different so I can't move it.
Maybe someone encountered the same problem and can help me.
Thank you.
In iOS 9 there is a new window for keyboard named UIRemoteKeyboardWindow, so when you are using accessoryView.superview you will get a wrong view.
To get correct view try to find it from window hierarchy directly:
(objective-c code)
-(UIView*)getKeyboardInputView {
if([[UIDevice currentDevice].systemVersion floatValue] >= 9.0) {
for(UIWindow* window in [[UIApplication sharedApplication] windows])
if([window isKindOfClass:NSClassFromString(#"UIRemoteKeyboardWindow")])
for(UIView* subView in window.subviews)
if([subView isKindOfClass:NSClassFromString(#"UIInputSetHostView")])
for(UIView* subsubView in subView.subviews)
if([subsubView isKindOfClass:NSClassFromString(#"UIInputSetHostView")])
return subsubView;
} else {
return accessoryView.superview;
}
return nil;
}
P.S. Taken from DAKeyboardControl https://github.com/danielamitay/DAKeyboardControl/pull/98
It seems that one particular aspect of iOS programming is to diagnose these weird, seemingly trivial yet frustratingly obscure small problems.
So today, I was happily woking on my recent iOS project, and I decided to upgrade my project to the latest version ECSlidingViewController, what harm could it do right? Just update a few deprecated methods that's all.
So I did all of that. Everything works fine, beautiful. However, I noticed that the status bar is behaving strangely! It is not appearing when I display one of my underLeftViewController, and it is in a weird shade when I push segue that particular underLeftViewController into one of its subsequent VC. What?? How could this be happening? Anyway, a picture is worth a thousand words:
So here is it acting nice and normal:
Now it disappears!!!:
Now it has a weird shade!!!:
And here is a picture of the app with the sliding view controller slided out:
I must have done something crazy to my status bar somewhere, then I thought.
So I looked into my implementation file for the VC where statusbar is acting crazy. It is in fact a subclass of UINavigationController, and its viewDidLoad is empty except with the [super viewDidLoad] line. So nothing suspicious here.
The run test page is in fact the rootViewController for the navVC, so I looked into it. I put all of my view setup code in its viewDidLoad, and this is what it looks like:
- (void)viewDidLoad
{
[super viewDidLoad];
// remove advanced button
self.navigationItem.rightBarButtonItem = nil;
self.navigationController.view.layer.shadowOffset = CGSizeMake(1, 0);
// setupGaugeView
[self setupGauge];
// add run test button
[self setupRunTestButton];
// setup notification container
CGRect notificationContainerFrame;
if ([WRGlobalHelper currentDeviceVersion] >= 7) {
CGFloat statusBarHeight = [WRGlobalHelper statusBarHeight];
notificationContainerFrame = CGRectMake(0, [[self.navigationController navigationBar] bounds].size.height+statusBarHeight, self.view.bounds.size.width, 1);
for (UIView *subview in self.view.subviews) {
CGRect newFrame = subview.frame;
newFrame.origin.y += [WRGlobalHelper statusBarHeight];
subview.frame = newFrame;
}
} else {
notificationContainerFrame = CGRectMake(0, [[self.navigationController navigationBar] bounds].size.height, self.view.bounds.size.width, 1);
}
self.notificationContainerView = [[UIView alloc] initWithFrame:notificationContainerFrame];
self.notificationContainerView.clipsToBounds = NO;
self.notificationContainerView.layer.backgroundColor = [UIColor clearColor].CGColor;
[self.view addSubview:self.notificationContainerView];
// some other unrelated stuff omitted....
}
And the `viewDidLoad's for the VCs where the status bar is acting normal or bizarre but with shade is all quite plain as well, they look like
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.view addGestureRecognizer:self.slidingViewController.panGesture];
}
Mind blown and I give up at this point. I've spent nearly 2 hours on this single issue already, and my brain hurts at the thought of the disappearing status bar. The almighty and omniscient SO, please help me! Thank you very much!
The status bar is not disappering, the text is just changing its color based on its assigned Style.
This answer will help
Could you tell me how to right align UISearchbar text in iOS 7? , I was using this in iOS6 but now it does not work in iOS7:
//hacking search bar
UITextField *searchField;
for (UIView *subview in self.searchBar.subviews)
{
if ([subview isKindOfClass:[UITextField class]]) {
searchField = (UITextField *)subview;
break;
}
}
if (searchField) {
searchField.textAlignment = NSTextAlignmentRight;
}
Unfortunately this cannot be done safely without completely re-implementing the class from scratch, as text alignment is adjusted by the internals of the object's code when the user begins and finishes editing.
The closest thing to what you want to do would be to use the three position adjustments to shift the text horizontally, but this doesn't affect alignment, only absolute position, and even then only when the user is typing.
If you want to try this, look up searchTestPositionAdjustment, setPositionAdjustment:forSearchBarIcon:, and searchFieldBackgroundPositionAdjustment. I don't think it will be of much use to you though.
-Ash
It's too late, but if anyone is still wondering the solution, then you can follow this.
UITextField *searchTextField = [searchBarController.searchBar valueForKey:#"_searchField"];
You can get the search field using above code. Now simply use the properties you want to use, like.
searchTextField.layer.cornerRadius = 10.0f;
searchTextField.textAlignment = NSTextAlignmentRight;
I've got a solution to this problem. It's a bit hacky and not very neat, but it does the trick.
Since UISearchBar itself does not allow you to edit the placeholder, I've set a UITextField underneath it and disabled it from any touches by doing this:
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if([touch.view isDescendantOfView:self.placeHolderTextField]){
return NO;
}
return YES;
}
Note: don't forget to include <UIGestureRecognizerDelegate> in your .h file.
If this doesn't work however, you can always use [self.view sendSubViewToBack:self.placeholderTextField];
Next on, I've just set events on which I want to display the placeholder and when not.
In the viewDidLoad, I'm just calling self.placeHolderTextFiew.placeholder = #"search"
And in
-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
if(searchText.length > 0){
self.placeHolderTextfield.placeholder = #"";
} else{
self.placeHolderTextfield.placeholder = #"search";
}
}
Note again: Make sure to include <UISearchBarDelegate> in your .h file in order for this to work.
I am using a tableView as well, so when the method DidSelectRowAtIndexPath is called, I'm also setting the placeholder to an empty string.
Hope this helps.
you can try like this also..
searchbar.placeholder = #"Hai.. whitespace ";
way to set text right align
searchbar->attribute inspector->search text->custom offset->horizontal(set as per requirement)
After playing with subviews of UISearchBar I found this solution, it works for iOS 6 and iOS 7
//hacking search bar
UITextField *searchField;
for (UIView *subview in self.searchBar.subviews)
{
//this will work in iOS 7
for (id sub in subview.subviews) {
if([NSStringFromClass([sub class]) isEqualToString:#"UISearchBarTextField"])
{
[sub setTextAlignment:NSTextAlignmentRight];
}
}
//this will work for less than iOS 7
if ([subview isKindOfClass:[UITextField class]]) {
searchField = (UITextField *)subview;
break;
}
}
//for less than iOS 7
if (searchField) {
searchField.textAlignment = NSTextAlignmentRight;
}
I'm making an app in Adobe AIR targeting iOS 4.0+ and Android 2.3+. I've tried to disable iOS elastic scrolling for the embedded YT video: When the user presses the player's IFrame the whole video pans over and I can't seem to find a way around this.
I've tried adding event listeners to prevent this behavior but it doesn't work.
By the way, I'm aware that I can't really control what happens in the IFrame. A quick and dirty solution would be to put elements directly over the frame, like a transparent canvas or a div that would catch the events. Not ideal at all, because users won't be able to press the buttons on the player.
Any ideas or suggestions?
Thanks!
I found a solution.
You need access to UIWebView (the underlying iOS implementation under StageWebView) to disable elastic scrolling.
Once you have your Adobe Native Extension (ANE) setup, its relatively simple. (A great ANE Wizard/Generator is found here https://github.com/freshplanet/ANE-Wizard)
For iOS 5 its straightforward: webView.scrollView.bounces = NO;
If you want to support iOS 4, it gets a bit more complex. You don't have the convenience of webView.scrollView, so you need to find this view manually.
An Objective-C code block that handles both iOS 4 and 5 would be something like this:
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
if ([currSysVer compare:#"5.0" options:NSNumericSearch] != NSOrderedAscending) {
// iOS 5 is straightforward
webView.scrollView.bounces = NO;
}
else {
// iOS 4 requires a bit more of work
UIScrollView *scrollView = nil;
for (UIView *subview in [webView subviews])
{
if ([subview isKindOfClass:[UIScrollView class]]) {
scrollView = (UIScrollView *)subview;
}
}
if (scrollView != nil) {
scrollView.bounces = NO;
}
}
Hope this helps!