I am using the following code to remove the toolbar from the iPhone keyboard when it is displayed.
- (void) keyboardDidShowNotification:(NSNotification *)aNotification {
NSArray *array = [[UIApplication sharedApplication] windows];
for (UIWindow* wind in array) {
for (UIView* currView in wind.subviews) {
if ([[currView description] hasPrefix:#"<UIPeripheralHostView"]) {
for (UIView* perView in currView.subviews) {
if ([[perView description] hasPrefix:#"<UIWebFormAccessory"]) {
[perView removeFromSuperview];
}
}
}
}
}
}
This is removing the toolbar like I want but it is still leaving a 1px border above where the toolbar use to be. How do I remove that as well?
Also this only appears to be an issue on iPhone Retina displays. iPhone 3GS and iPad Retina do not have it.
Seems to be a bug in removeFromSuperView. I had the same problem when adding a toolbar as an input accessory view to some pickers for inline editing. Calling 2x removeFromSuperView left the border.
Using [self.view endEditing:YES] when closing the picker helped to clean up the picker and the accessory view attached to it, with no border. Perhaps this can point you into the right direction?
Related
I'm trying to create a custom keyboard for a UITextField, the background of this inputView should be transparent, I have set the background color in the view's xib file to "clear color". It is working great on iOS 6 and earlier.. but on iOS 7 it not working
Any idea how can I make it work? I want it to be fully transparent
This will set the backdrops opacity to zero when displaying your custom keyboard and reset it back to 1 when the normal keyboard is shown.
+ (void)updateKeyboardBackground {
UIView *peripheralHostView = [[[[[UIApplication sharedApplication] windows] lastObject] subviews] lastObject];
UIView *backdropView;
CustomKeyboard *customKeyboard;
if ([peripheralHostView isKindOfClass:NSClassFromString(#"UIPeripheralHostView")]) {
for (UIView *view in [peripheralHostView subviews]) {
if ([view isKindOfClass:[CustomKeyboard class]]) {
customKeyboard = (CustomKeyboard *)view;
} else if ([view isKindOfClass:NSClassFromString(#"UIKBInputBackdropView")]) {
backdropView = view;
}
}
}
if (customKeyboard && backdropView) {
[[backdropView layer] setOpacity:0];
} else if (backdropView) {
[[backdropView layer] setOpacity:1];
}
}
+ (void)keyboardWillShow {
[self performSelector:#selector(updateKeyboardBackground) withObject:nil afterDelay:0];
}
+ (void)load {
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:#selector(keyboardWillShow) name:UIKeyboardWillShowNotification object:nil];
}
I am chasing the same issue, as I have a numeric keypad which fills only the left half of the screen in landscape mode (and is basically unusable on iOS7 where the blur effect covers the entire width of the screen). I haven't quite figured out how to get what I want (blurred background only behind my actual inputView), but I have figured out how to disable the blur entirely:
Define a custom subclass of UIView and specify that in your xib file
In this class override willMoveToSuperview: as follows
- (void)willMoveToSuperview:(UIView *)newSuperview
{
if (UIDevice.currentDevice.systemVersion.floatValue >= 7 &&
newSuperview != nil)
{
CALayer *layer = newSuperview.layer;
NSArray *subls = layer.sublayers;
CALayer *blurLayer = [subls objectAtIndex:0];
[blurLayer setOpacity:0];
}
}
This appears to impact the background of every custom inputView I have (but not the system keyboard) so you might need to save/restore whatever the normal opacity value is when your inputView gets removed from the superview if you don't want that.
iOS 7 is doing some things under the hood that are not documented. However, you can examine the view hierarchy and adjust the relevant views by overriding -willMoveToSuperview in your custom input view. For instance, this code will make the backdrop transparent:
- (void)willMoveToSuperview:(UIView *)newSuperview {
NSLog(#"will move to superview of class: %# with sibling views: %#", [newSuperview class], newSuperview.subviews);
if ([newSuperview isKindOfClass:NSClassFromString(#"UIPeripheralHostView")]) {
UIView* aSiblingView;
for (aSiblingView in newSuperview.subviews) {
if ([aSiblingView isKindOfClass:NSClassFromString(#"UIKBInputBackdropView")]) {
aSiblingView.alpha = 0.0;
}
}
}
}
How can I hide the volume bar in movie player and keep the other controls are appear (play, forward ... ) ? I want to show some videos that haven't any sounds, so the volume bar is totally will be useless.
can I do this ?
Thanks in advance
Set the controlStyle of the MPMoviePlayer to MPMovieControlStyleNone.
moviePlayer.controlStyle = MPMovieControlStyleNone;
But this will hide all the controls from the view.
After setting to MPMovieControlStyleNone, if you want to display the play/pause option and seek bar, You need to add custom controls.
(I did it before, I used slider as seek bar and and placed it in a UIToolBar along with a Tool bar button . Button is for play/pause option)
MPMovieControlStyle
Constants describing the style of the playback controls.
enum { MPMovieControlStyleNone, MPMovieControlStyleEmbedded,
MPMovieControlStyleFullscreen, MPMovieControlStyleDefault =
MPMovieControlStyleFullscreen }; typedef NSInteger
MPMovieControlStyle;
Constants
MPMovieControlStyleNone
No controls are displayed.
Available in iOS 3.2 and later.
Declared in MPMoviePlayerController.h.
MPMovieControlStyleEmbedded
Controls for an embedded view are displayed. The controls include a start/pause button, a scrubber bar, and a button for toggling
between fullscreen and embedded display modes.
Available in iOS 3.2 and later.
Declared in MPMoviePlayerController.h.
MPMovieControlStyleFullscreen
Controls for fullscreen playback are displayed. The controls include a start/pause button, a scrubber bar, forward and reverse
seeking buttons, a button for toggling between fullscreen and embedded
display modes, a button for toggling the aspect fill mode, and a Done
button. Tapping the done button pauses the video and exits fullscreen
mode.
Available in iOS 3.2 and later.
Declared in MPMoviePlayerController.h.
MPMovieControlStyleDefault
Fullscreen controls are displayed by default.
Available in iOS 3.2 and later.
Declared in MPMoviePlayerController.h.
Refer MPMoviePlayerController
There is no way to do this except "hacking" the subviews. You may subclass MPMoviePlayerViewController and iterate the subviews. In one of my apps, I used code like this to remove things like the media controls:
- (void)removeMediaControls
{
#try
{
// Search for the MPSwipeableView
for (UIView *view1 in [self.view subviews])
{
// Check for the MPSwipeableView
if ([[[view1 class] description] isEqualToString:#"MPSwipableView"])
{
// Search for the MPVideoBackgroundView
for (UIView *view2 in [view1 subviews])
{
// Check for the MPVideoBackgroundView
if ([[[view2 class] description] isEqualToString:#"MPVideoBackgroundView"])
{
// Search for the UIView
for (UIView *view3 in [view2 subviews])
{
// Check for the MPWildcatFullScreenVideoOverlay
if ([[[view3 class] description] isEqualToString:#"MPWildcatFullScreenVideoOverlay"])
{
// Search for the MPWildcatFullScreenNavigationBar
for (UIView *view4 in [view3 subviews])
{
// Check for the UIImageView
if ([[[view4 class] description] isEqualToString:#"UIImageView"])
{
// Remove the overlay
[view4 removeFromSuperview];
}
}
}
}
}
}
}
}
}
#catch (NSException * e)
{
}
}
The code above is too old, it worked with iOS 4.3. On iOS 5 and iOS 6 the view hierarchy changed, so you may have to updated your code with every new iOS version. See also: MPMoviePlayerController hide volume slider
I noticed an strange issue with my application that only occurs on the iPhone 3G and iPhone 3GS. I am creating a scroll view with two pages. On the second page of the scroll, when you try to scroll the picker, it is very unresponsive. It kinda appears that my application can't distinguish between the scrolling of the picker and the scrolling of the scrollview, because sometimes you scroll up and it goes to the left.
Please keep in mind, this works great on the iPhone 4 and iPhone 4S.
Has anyone ran into this problem before or any idea of what is actually going on?
Apparently the UIScrollView and UIPickerView cause problems if used together. However, this only occurred on the iPhone 3 and iPhone 3GS.
The solution was to subclass UIScrollView and implement the following method.
- (UIView *)hitTest:(CGPoint)point
withEvent:(UIEvent *)event
{
UIView *result = [super hitTest:point withEvent:event];
if ([result.superview isKindOfClass:[UIPickerView class]]) {
self.canCancelContentTouches = NO;
self.delaysContentTouches = NO;
}
else {
self.canCancelContentTouches = YES;
self.delaysContentTouches = YES;
}
return result;
}
You should only enable armv7 in your build settings (not armv6), that's all
Add a UIView over scroll view, over UIView add UIPickerView.
Is there a way to get a black keyboard? The default one is bluish. And the Alert style one is semi-transparent black. I was wondering if it was possible to have the keyboard black, e.g. non transparent. Or do I have to pull up a black view behind the keyboard to reduce the transparency effect?
The short answer is, NO. The only two keyboards you can display are the normal and alert style keyboards.
There are ways to hack around, get the ui keyboard and change it's composition. I wouldn't recommend doing this as it will 1) likely make have your app rejected from the app store and 2) likely break the next time an iOS revision comes around.
Seems like putting a black or white view behind the keyboard should work for application. In this case I would recommend looking here for a way to animate that black view up below the keyboard.
As Ben states above you can just use one of these two values:
[textView setKeyboardAppearance:UIKeyboardAppearanceAlert];
[textView setKeyboardAppearance:UIKeyboardAppearanceDefault];
Here is code to remove the UIKeyboard background by hiding it. Feel free to modify it to tint the UIKeyboard:
-(NSArray*)subviewsOfView:(UIView*)view withType:(NSString*)type{
NSString *prefix = [NSString stringWithFormat:#"<%#",type];
NSMutableArray *subviewArray = [NSMutableArray array];
for (UIView *subview in view.subviews) {
NSArray *tempArray = [self subviewsOfView:subview withType:type];
for (UIView *view in tempArray) {
[subviewArray addObject:view];
}
}
if ([[view description]hasPrefix:prefix]) {
[subviewArray addObject:view];
}
return [NSArray arrayWithArray:subviewArray];
}
-(void)removeKeyboardBackground{
for (UIWindow *keyboardWindow in [[UIApplication sharedApplication] windows]) {
for (UIView *keyboard in [keyboardWindow subviews]) {
for (UIView *view in [self subviewsOfView:keyboard withType:#"UIKBBackgroundView"]) {
view.hidden=YES;
}
}
}
}
Just call [self removeKeyboardBackground] after you received a NSNotification for UIKeyboardDidShowNotification. Do whatever you want with the background view by replacing view.hidden=YES; with whatever you would like.
I have placed following javascript in my html file.
<script TYPE="text/javascript">
function srk(){
document.ontouchmove = function(e){
e.preventDefault();
}
}
</script>
I am scrolling my webview by following code with some animation.
[myWebView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat: #"window.scrollTo(0,%i);",414*self.initialScrollPosition]];
Everything going right, but on problem that I am facing is as follows.
Whenever User/I tap on the status bar of iPhone, WebView Bydefault scrolls to top.
This should not be done.
Is it possible to prevent inbuilt functionality ?
I know one of the option is as follows.
((UIScrollView *)[[myWebView valueForKey:#"_internal"] valueForKey:#"scroller"]).scrollsToTop = NO;
But is it valid to do ?
You can add a very tiny UIScrollView in the window. Then tapping the status bar won't scroll the web view to top.
A more straightforward way to do this would be to set the scrollsToTop property of the UIScrollView in the WebView to NO.
for(UIView *view in [myWebView subviews]) {
if([view isKindOfClass:([UIScrollView class])]) {
[(UIScrollView *)view setScrollsToTop:NO];
}
}
I have tested this on iOS 4.0 and 4.3 (iOS 5 seems to not need this).
adapted from this.