Custom Keyboard: inputView: how to change the Keyboard size? - textfield

I implemented the textfield with a custom keyboard with the "setInputView" function.
But i have a problem: my keyboard frame is not a standard iphone keybord frame.
The question is:
How can i change the size of my custom keyboard?
I know some functions like: UIKeyboardFrameBeginUserInfoKey, ..etc.
Please Note:
The iPhone keyboard frame is = 0,264,320,216
My custom keyboard frame is = 0,0,320,460
Hoping for your kind collaboration,
Best regards...
P

It turns out that the default behaviour of the custom input view that you assign to the UITextField's property is to resize the view to the same frame as the default keyboard. Try setting (I use the name InputViewController for my input view, but you can use whatever you want):
inputViewController = [[InputViewController alloc] initWithNibName:#"InputViewController" bundle:nil];
inputViewController.delegate = self;
inputViewController.view.autoresizingMask = UIViewAutoresizingNone; // This is the code that will make sure the view does not get resized to the keyboards frame.
For more detailed information, you can look at this link, which is provided by Apple.:
If UIKit encounters an input view with an UIViewAutoresizingFlexibleHeight value in its autoresizing mask, it changes the height to match the keyboard.
Hope that Helps!

To set the keyboard inputView with the same size as the native keyboard just do this:
inputView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
To set your own frame do this:
inputView.autoresizingMask = UIViewAutoresizingNone;
From Apple:
You have a lot of flexibility in defining the size and content of an input view or input accessory view. Although the height of these views can be what you’d like, they should be the same width as the system keyboard. If UIKit encounters an input view with a UIViewAutoresizingFlexibleHeight value in its autoresizing mask, it changes the height to match the keyboard. There are no restrictions on the number of subviews (such as controls) that input views and input accessory views may have. For more guidance on input views and input accessory views, see iOS Human Interface Guidelines.

I had the same problem. I solved it by registering for UIKeyboardDidShowNotification (UIKeyboardWillShowNotification did not work, unfortunately) and then changing the view size after the keyboard was shown. However, it still had the white box on top of the keyboard when it was moving up. This worked fine for me because it is coming in over a UITextView with a white background. If you were coming in over any other colored objects, however, it would look a little ugly before the view was properly resized. You can solve that by setting the background color to clearColor.
// Add this while initializing your view
self.backgroundColor = [UIColor clearColor]; // Needed because we can't resize BEFORE showing the view. Otherwise you will see an ugly white box moving up w/ the keyboard
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWasShown:)
name:UIKeyboardDidShowNotification object:nil];
// Called when the UIKeyboardDidShowNotification is sent.
- (void)keyboardWasShown:(NSNotification*)aNotification
{
CGRect rect = self.frame;
rect.size.height = 164;
self.frame = rect;
}

Also if you're using a UIViewController to design your inputView, don't use the UIViewController.view... it seems to have a lot of problems getting resized incorrectly on rotate regardless of the AutoresizeMask.
What worked for me was to take my existing UI and use Editor > Embed In > View. Then create a new outlet, and pass that outlet as the inputView. Suddenly the resize on rotate bugs disappeared.

For me msgambel's solution didn't work. But the approach right, I was playing with the inputView's autoresizingMask. Former I had different setting, but the right way to avoid white extra space over the custom keyboard is:
I applied this just for the outermost view.

Related

Drag And Swap Two UIScrollViews (Hover & Swap Effect)

I am creating a photo editor in my app and working on a multiple picture layout option.
Currently when the user takes a picture, I display their image in UIImageView nested in a UIScrollView. The reason I nest it in a UIScrollView is so I can pan and zoom.
In the situation where the user selects duo layout mode, the app puts 2 images side by side (so 2 UIScrollViews).
If they hold a finger on one UIScrollView I want to raise the UIScrollView up a tad and give it a drop shadow.
I have a long way of doing this, but I was curious if there was anything in the native libraries that will let me automatically create this hover effect for dragging a view class.
Thanks
No, there isn't any preexisting functionality for this. You can add shadow and animate a "lift" motion yourself with something like this:
// define dragged somewhere as the UIView subclass of your choosing
dragged.layer.shadowColor = [UIColor blackColor].CGColor;
dragged.layer.shadowOffset = CGSizeMake(-2, 2);
dragged.layer.masksToBounds = NO;
dragged.layer.shadowRadius = 4;
dragged.layer.shadowOpacity = .7;
[UIView animateWithDuration:.2 delay:0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{self.draggedPhoto.transform = CGAffineTransformMakeScale(1.2, 1.2);}
completion:nil];

Force NSScrollView to use NSScrollerStyleOverlay independently from input device

How to force NSScrollView to use scrollers like that:
independently from input device, because now if computer has wired mouse connected or app is running on laptop (macbook) it uses scrollers like this:
witch is always visible. It is possible to achieve my desired result if user changes settings in system preferences. But I need to have that result without changing anything. Or maybe there is some easy method to use custom NSScrollers?
Hiding scrollers would be pretty acceptable result, but when I hide them I have some scrolling issues. I use custom NSClipView witch adjusts documentView to be centered when adjusting its frame size. But when I adjust frame size, and it is scrolled to center, if I scroll anywhere it jumps to bottom left corner and then works as it should.
I'm using table view and I just put this code in awakeFormNib:
[[self.tableView enclosingScrollView] setScrollerStyle:NSScrollerStyleOverlay];
I also tried to hide scrollers but then I couldn't scroll the content using trackpad (no problem using mouse). In the other project I have similar table view with the same settings and hiding scrollers doesn't cause any issues.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(notify:) name:NSPreferredScrollerStyleDidChangeNotification object:nil];
- (void)notify:(NSNotification*)
{
__weak typeof(self) weakself = self;
dispatch_async(dispatch_get_main_queue(), ^{
weakself.scrollView.scrollerStyle = NSScrollerStyleOverlay;
});
}

Vertical UIToolBar and also its UIBarButtonItem

In my application i have one UIToolBar. When in portrait mode this toolbar is on top and is horizontal, but when the device is rotated this toolbar should be converted to vertical toolbar and should be place on left side. Also its subviews i.e 5 UIBarButtonItems should also be placed accordingly.
Does any one know the solution for this ?
I have read this for reference, But my tool bar should align itself according to the orientation. I am using iOS 6.
There is no built-in vertical menu feature (yet). There are 2 parts in your question:
Vertical UIToolbar:
You may restrict the device orientation and the toolbar will remain at the same location
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
(this will affect all views)
Or you can listen for orientation changes and rotate your toolbar accordingly using its transform property, e.g.
toolbar.transform = CGAffineTransformRotate(CGAffineTransformIdentity, M_PI/2);
Rotated UIBarButtonItem:
If you have rotated the toolbar (case 2 above), items will rotate too.
If not, you need to rotate your items. Several post shows how to deal with the fact that as UIBarButtonItem does not extend UIView, it has no transform property (see here). In the end you will have again to listen for orientation changes and rotate the subviews of your toolbar, e.g.
for (UIView *view in toolbar.subviews) {
view.transform = CGAffineTransformRotate(CGAffineTransformIdentity, M_PI/2);
}
Of course apply the rotation related to your orientation (M_PI/2 or -M_PI/2).
I ran into this same issue, so I subclassed UIToolbar and made it into exactly what I wanted it to be.
Here's the GitHub link: https://github.com/fennelouski/NKFToolbar

Draw Over Image

I'm working on some drawing code. I have that portion working great.
I want to draw over an image, but I want to still be able to see the detail of the image, the black lines, etc.
What I am working on is making a transparent UIImageView that holds the image.
I'm not sure how to get this set up properly though.
Should this be added above the other UIImageView that I color on or below it?
Here's what I have so far:
- (void)viewDidLoad
{
[super viewDidLoad];
topImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 46, 320, 370)];
[topImageView setImage:[UIImage imageNamed:#"imagesmall.png"]];
topImageView.alpha = 1.0;
topImageView.layer.opacity = 1.0;
topImageView.layer.opaque = NO;
[self.view addSubview:topImageView];
[topImageView release];
}
Thoughts anyone?
Yes, you can draw views over other views. They are drawn in the order that they're added as subviews, unless you reorder them after that.
You may need to set the opaque property for some views (this is distinct from and overrides their layer opacity), and set their backgroundColor to nil. UIImageView seems to be transparent by default, as long as its image is; some other UIView subclasses are not.
So, just what is your overlay going to be? If you just need to display one image over another, what you have here seems to work already. If you need to draw some lines programmatically, you'll need to do this:
Create a subclass of UIView.
Implement its drawRect method to display the content you need.
When you add your custom view on top of the background image, make sure it is not opaque and has no backgroundColor.
A common problem here is to find that your foreground is working, but the background isn't being loaded properly. To make sure the background is there, set the alpha of the foreground view to 0.5. You won't want to do that in production, but it will allow you to verify that both views exist.

UIPickerView background color not changed?

I want to change the picker view bakground color. I try this way but not worked.
doublePicker.backgroundColor = [self RGBColorR:85 G:17 B:92];
- (UIColor *)RGBColorR:(double)red G:(double)green B:(double)blue {
return [UIColor colorWithRed:(red/255.00) green:(green/255.00) blue:(blue/255.00) alpha:1.00];
}
I want to do picker view like in picture. How can I do this? Thanks for your reply.
you can add subviews over certain areas of your pickerview..
use:
[picker addSubview: coverView]; //adding subviews to different area of the picker
you're going to find yourself playing with alot of CGRect to get thing to fit properly. If you want to change the entire thing you're going to have to override some methods that handle the touch events etc..
this tutorial might help you create a custom picker
https://developer.apple.com/iphone/library/samplecode/UICatalog/
You cannot change the appearance of UIPickerView, even the size, it's the most unchangeable UI element in iOS. Best you can do is build custom by yourself, using UIScrollView with paging enabled.