ios 8 UITextField hides under Predictive View in iOS 8 - iphone

I am developing a chat application in which I have UIView with UITableView and at the bottom of the UIView there is another UIView(say userInputView) with a UITextField and a UIButton added as a subview on it.
When the user taps on the UITextField keyboard appears and this UIView(userInputView) moves up to adjust itself as per keyboard height using UIKeyboardDidChangeFrameNotification.
When I tap the "Send" Button, I set the text of UITextField to nil.
This is working fine till iOS 7 but in iOS 8 when I change the text of the UITextField the userInputView view is hiding under predictive text view. When I minimize the predictive text view then userInputView is displayed again but when I maximize predictive textview it hides again.
All of this is happening when I try to change to change the text of UITextField on tapping the send button. If I don't change the text of UITextField then it works fine.
How can I resolve this issue in iOS8? Even if I hide predictive text view the userInputView will hide and never display again.

I have the same issue as yours but after checking the keyboard notifications enums.So,I used UIKeyboardDidChangeFrameNotification or UIKeyboardWillChangeFrameNotification because these will tell you the change in keyboard frame when predictive text bar gets up or down when keyboard is in view or user turn on or turn off from setting. Below is the code which working perfectly.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardFrameDidChange:)
name:UIKeyboardDidChangeFrameNotification object:nil];
-(void)keyboardFrameDidChange:(NSNotification*)notification{
NSDictionary* info = [notification userInfo];
CGRect kKeyBoardFrame = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
if (kKeyBoardFrame.size.height == HEIGHT_OF_KEYBOARD) {
[viewCommentText setFrame:CGRectMake(0, kKeyBoardFrame.size.height+32, 320, viewCommentText.frame.size.height)];
}else if (kKeyBoardFrame.size.height == 224){
[viewCommentText setFrame:CGRectMake(0, kKeyBoardFrame.size.height+18, 320, viewCommentText.frame.size.height)];
}else{
[viewCommentText setFrame:CGRectMake(0, kKeyBoardFrame.size.height-viewCommentText.frame.size.height, 320, viewCommentText.frame.size.height)];
}
}
and also remove observer when you are leaving your view
#pragma mark Device constrols Constant
#define HEIGHT_OF_STATUS_BAR 20
#define HEIGHT_OF_TOOLBAR 44
#define HEIGHT_OF_TABLE_CELL 44
#define HEIGHT_OF_TAB_BAR 49
#define HEIGHT_OF_SEARCH_BAR 44
#define HEIGHT_OF_NAVIGATION_BAR 44
#define HEIGHT_OF_TEXTFIELD 31
#define HEIGHT_OF_PICKER 216
#define HEIGHT_OF_KEYBOARD 216
#define HEIGHT_OF_SEGMENTED_CONTROL 43
#define HEIGHT_OF_SEGMENTED_CONTROL_BAR 29
#define HEIGHT_OF_SEGMENTED_CONTROL_BEZELED 40
#define HEIGHT_OF_SWITCH 27
#define HEIGHT_OF_SLIDER 22
#define HEIGHT_OF_PROGRESS_BAR 9
#define HEIGHT_OF_PAGE_CONTROL 36
#define HEIGHT_OF_BUTTON 37

Related

How to move a Textfield and Button placed by Interface Builder

I have a textfield and button that are placed by me in Interface Builder for the 3.5 inch iPhone. Im checking programmatically to see if it is an iPhone 5, if it is then the textfield and button. I have "Autoresize Subviews" unchecked on the View Controller, textfield, and button. The code I have is in the viewDidLoad, and if it is an iPhone 5, it hits the lines but doesn't move the textfield or button.
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 568)
{
self.chatBox.frame = CGRectMake(20,509,201,30);
self.submitButton.frame = CGRectMake(227,504,73,39);
[self.view addSubview:self.chatBox];
[self.view addSubview:self.submitButton];
}
}
If you are using autolayout your constraints may be taking precedence over your code above. Without auto layout, I used this code:
int adjustY=44;
CGPoint iPhone5center=CGPointMake(theButton.center.x,theButton.center.y+adjustY);
theButton.center=iPhone5center;
See this question for more details. I am having a problem using it with auto layout in a scroll view.
The problem you're having here is that the frame is being overridden by Auto Layout. Before adjusting the frame on a view using auto layout, add the following line of code:
[self setTranslatesAutoresizingMaskIntoConstraints:YES];
This should translate whatever frame you set into new constraints and update them. If you don't want to translate them into constraints, obviously just pass 'NO' to this message to achieve this.

millenial media ads banner tap not working in iphone and Ads pops modalview controller after 60 secs

i 've implemented millennial media framework, it's working. but the ads pop up coming after every 60secs of timer. and i see only white banner and tap is not working. i 've implemented all delegates and banner is the superview there is no view on top of it. i want a ads banner which displays add and a Ads model to appear on clicking on it..
Your help is greatly appreciated, here is the code i 've used to add bannerview.
Thanks
// Create a 320 x 53 frame to display iPhone ads, or a 768 x 90 frame to display iPad ads
CGRect adFrame = ((IS_IPHONE5) ? CGRectMake(0, 451, 320, 53): CGRectMake(0, 363, 320, 53));
// Returns an autoreleased MMAdView object
bannerAdView_ = [[MMAdView adWithFrame:adFrame
type:MMBannerAdBottom
apid:BANNER_APID
delegate:self // Must be set, CANNOT be nil
loadAd:YES // Loads an ad immediately
startTimer:YES] retain]; // Start timer to auto refresh the ad view
bannerAdView_.rootViewController = self; // you must set the rootViewController
[MMAdView setLogLevel: MMLOG_LEVEL_INFO | MMLOG_LEVEL_DEBUG];
[self.view addSubview:bannerAdView_];

Add Text in Statusbar [iOS Cydia App] [duplicate]

Is it possible to add a UIView on the staus bar of size (320 x 20)? I don't want to hide the status bar, I only want to add it on top of the status bar.
You can easily accomplish this by creating your own window above the existing status bar.
Just create a simple subclass of UIWindow with the following override of initWithFrame:
#interface ACStatusBarOverlayWindow : UIWindow {
}
#end
#implementation ACStatusBarOverlayWindow
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
// Place the window on the correct level and position
self.windowLevel = UIWindowLevelStatusBar+1.0f;
self.frame = [[UIApplication sharedApplication] statusBarFrame];
// Create an image view with an image to make it look like a status bar.
UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:self.frame];
backgroundImageView.image = [UIImage imageNamed:#"statusBarBackground.png"];
[self addSubview:backgroundImageView];
[backgroundImageView release];
// TODO: Insert subviews (labels, imageViews, etc...)
}
return self;
}
#end
You can now, for example in a view controller in your application, create an instance of your new class and make it visible.
overlayWindow = [[ACStatusBarOverlayWindow alloc] initWithFrame:CGRectZero];
overlayWindow.hidden = NO;
Be aware of messing with the window key status by using - (void)makeKeyAndVisible or similar. If you make your main window (the UIWindow in your Application Delegate) loose key status, you will encounter problems with scrolling scrollviews to top when tapping the status bar etc.
I wrote a static library mimicing Reeders status bar overlay, you can find it here: https://github.com/myell0w/MTStatusBarOverlay
It currently supports iPhone and iPad, default and opaque black status bar styles, rotation, 3 different anymation modes, history-tracking and lots of more goodies!
Feel free to use it or send me a Pull Request to enhance it!
All answers looks like working, but in iOS6.0 I have next problems:
1/ Rotations looks bad
2/ Window (status bar is kind of Window) needed rootViewController
I'm using answer from myell0w, but rotate works not good. I've just remove one extra window and using UIWindow from AppDelegate to implement status bar.
May be this solution is ok only for one UIViewController-app...
Ive implemented by the next way:
1/ In ApplicationDelegate:
self.window.windowLevel = UIWindowLevelStatusBar + 1;
self.window.backgroundColor = [UIColor clearColor];
self.window.rootViewController = _journalController;
2/ Create custom UIView and implement all that you need inside:
For an example touchable statusbar:
#interface LoadingStatusBar : UIControl
And easily create and add to your controller view:
_loadingBar = [[LoadingStatusBar alloc] initWithFrame:topFrame];
[self addSubview:_loadingBar];
3/ Some magic when add your controller view (in initWithFrame:)
CGRect mainFrame = self.bounds;
mainFrame.origin.y = 20;
self.bounds = mainFrame;
Your controller view will has 2 views - content view and status bar view. You can show status bar, or hide it when you want.
Frame of content view will be:
_contentView.frame = CGRectMake(0, 20, self.bounds.size.width, self.bounds.size.height);
4/ And one last magic here :)
To detect touches in non touchable area I've used:
-(id)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
if (point.y < 20) return _loadingBar;
return [super hitTest:point withEvent:event];
}
For now it works fine on iPad/iPhone and all iOS's from 4 to 6.
Just to dismiss the "You cannot do this comments"...
I don't know how but I know it is doable. The Feed reader app called Reeder does that.
As you can see from the screenshot, Reeder puts a small dot on the top right of the screen. When you tap it. The bar will fill the whole statusbar until you tap it again to make it small.
First of all, a big thank you to #Martin Alléus for providing the code for this implementation.
I'm just posting for a problem that I faced and the solution I used, as I believe others might experience the same issue.
If the App is started while an call is in place, the status bar height will be 40 pixels and this means that the custom status bar will be initialized with that height.
But if the call is ended while you are still in the app, the status bar height will remain still 40 pixels and it will look weird.
So the solution is simple: I've used the Notification center to subscribe to the status bar frame change delegate of the app and adjust the frame:
- (void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)oldStatusBarFrame {
//an in call toggle was done
//fire notification
[[NSNotificationCenter defaultCenter] postNotificationName:kStatusBarChangedNotification object:[NSValue valueWithCGRect:oldStatusBarFrame]];
}
And in the ACStatusBarOverlayWindow we subscribe to the notification:
-(id)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame]))
{
// Place the window on the correct level & position
self.windowLevel = UIWindowLevelStatusBar + 1.0f;
self.frame = [UIApplication sharedApplication].statusBarFrame;
self.backgroundColor = [UIColor blackColor];
//add notification observer for in call status bar toggling
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(statusBarChanged:) name:kStatusBarChangedNotification object:nil];
}
return self;
}
and our code to adjust the frame:
- (void)statusBarChanged:(NSNotification*)notification {
//adjust frame...
self.frame = [UIApplication sharedApplication].statusBarFrame;
//you should adjust also the other controls you added here
}
The kStatusBarChangedNotification is just a constant I've used for easy referrence, you can simply replace it with a string, or declare the constant globally.

UIToolbar on top of keyboard: Change frame?

I have a UIToolbar set to the inputAccessoryView of a UITextView. This shows the toolbar on top of the keyboard, when editing. I have, however, encountered a problem when rotating the device: the toolbar should become a little less heigh (32 pixels vs 44). When I just update the height of the toolbar, I get a little white space between the toolbar and the keyboard:
So I used -didRotateFromInterfaceOrientation: to also update the origin, and then it works when rotating from portrait to landscape. When rotating back up, however, the toolbar is 12 pixel too low and overlapping the keyboard:
By then, the origin is (0,0) again and setting a negative value didn't help. Any suggestions of how to make it work so that the toolbar changes its size and never overlaps?
I fixed it by calling [textView resignFirstResponder] in -willRotateToInterfaceOrientation:duration: and [textView becomeFirstResponder] in -didRotateFromInterfaceOrientation:. The system seems to adjust the frame properly.
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
didShowKeyboard = [self.textView isFirstResponder];
[self.textView resignFirstResponder];
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
CGRect toolbarFrame = [self.navigationController.toolbar bounds];
self.keyboardToolbar.frame = toolbarFrame;
if (didShowKeyboard)
[self.textView becomeFirstResponder];
}
Instead of Calculating the Origins and sizes you can use Autosizing to render the Controls during rotation.
See this tutorial http://www.bogotobogo.com/XcodeSDK-Chapter4.html
I think this can give you a hint.

UIWebView under transparent UINavigationBar

I have a UIWebView which I want to put under my translucent UINavigationBar. Normally when I put a UIScrollView under a translucent UINavigationBar, I set its contentOffset such that all content will be initially pushed after the bar so that it can be seen; thereafter, the user can scroll text and it will underlap the bar.
The problem is that UIWebView appears not to be a proper subclass of UIScrollView; thus, I can't use setContentOffset. Does anyone have any tips or tricks on getting a UIWebView to look good with a translucent navigation bar? Thanks.
As of iOS 5 you can use the scrollView property of UIWebView, and set a contentInset to adjust the positon.
CGFloat top = 0.0;
if( self.navigationController != nil && self.navigationController.navigationBar.translucent ) {
top = self.navigationController.navigationBar.bounds.size.height;
}
UIWebView* wv = ...
wv.scrollView.contentInset = UIEdgeInsetsMake(top, 0.0, 0.0, 0.0);
The easiest way is to set:
webView.clipsToBounds = NO;
webView.scrollView.clipsToBounds = NO;
It work on bouth iOS 7 & 6, and I didn't try, but on iOS 5 probably too
I achieved this by setting the UIWebView subviews to not clip to bounds, then I could put a toolbar on top of it and get the desired effect:
for (UIView *subview in theWebView.subviews) {
subview.clipsToBounds = NO;
}
I am not sure if there is a clean method to doing this. I have not tried it, but here is an idea:
draw the uiwebview at origin 0,0
intercept all screen touches
if you detect the user dragging up (scrolling up the webview), dont pass the touch on
Instead, move the webview up x pixels so its origin is (0,-x). Then change the height to add x pixels
Youy will need to keep some sort of state so that you know when to stop resizing the webview and start passing on the touches so the webview will scroll.
Getting it back is the same only you do it on a drag down (scrolling down the webview).
Another way to possibly do this is to insert a div in the html code you are rendering so that it is spaced out up on the top of the page. make sure you set your zoom correctly and set the uiwebviews origin to (0, -x) to begin with.
With the advent of iOS 7, the offset height would now need to include the height of the top status area. Otherwise, iOS7 devices will have 20 pixels of webview still hidden under the navigation bar.
In a project that needs to support iOS 7 and older devices, a macro like the one found
here:
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
Can be very useful.
A modified version of zerotool's helpful code listed above could now look something like this:
if (self.navigationController != nil && self.navigationController.navigationBar.translucent) {
top = self.navigationController.navigationBar.bounds.size.height;
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"7.0")) {
top += [[UIScreen mainScreen] applicationFrame].origin.y;
}
}
// (etc.)