Can I use scrollview.bounces property of webview for handling webview scroll? - objective-c

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;
}
}
}

Related

self.splitViewController.navigationController pushViewController can't work

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;
}
}
}
}
}
}

Capture dragging outside of UIControl -- UILongPressGestureRecognizer

I'm trying to implement an async voice recording feature. There's a button that has a UILongPressGestureRecognizer and this starts the recording. Right now, when they let go, the recording is saved and sent.
#pragma mark - Actions
- (void) recordButtonPressed:(UILongPressGestureRecognizer *)gesture
{
if (gesture.state == UIGestureRecognizerStateBegan) {
[self.voiceRecorderView.recordButton setImage:[UIImage imageNamed:kWSGreyDotXLarge] forState:UIControlStateNormal];
[self startRecording];
}
if (gesture.state == UIGestureRecognizerStateEnded) {
[self stopRecording];
[self.voiceRecorderView.recordButton setImage:[UIImage imageNamed:kWSPinkDotXLarge] forState:UIControlStateNormal];
}
}
This works, but now I need to copy the now standard feature of allowing the user to drag their finger off the button while it's pressed to cancel the recording.
How to add a gestureRecognizer to tell if a user drags outside the control but is still pressing it?
I hope it will work for you....
BOOL cancelflag;
UIButton *recordBtn;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(handleLongPress:)];
[longPress setDelegate:self];
[recordBtn addGestureRecognizer:longPress];
}
-(void)handleLongPress:(UILongPressGestureRecognizer *)longPressRecognizer
{
if(longPressRecognizer.state == UIGestureRecognizerStateBegan)
{
if (!stopBtnFlag)
{
if (!audioRecorder.recording)
{
[self performSelectorOnMainThread:#selector(setUpAudioRecorder) withObject:nil waitUntilDone:YES];
[audioRecorder record];
NSLog(#"Recording...");
}
stopBtnFlag = YES;
cancelflag =YES;
}
}
else if (longPressRecognizer.state == UIGestureRecognizerStateChanged)
{
[audioRecorder stop];
stopBtnFlag = NO;
NSLog(#"moved");
}
else if (longPressRecognizer.state == UIGestureRecognizerStateEnded)
{
if(cancelflag)
{
[audioRecorder stop];
[self playmusic];
}
}
}
#Jaleel's answer gave me a start. Here's a complete working version:
- (void) recordButtonPressed:(UILongPressGestureRecognizer *)gesture
{
if (gesture.state == UIGestureRecognizerStateBegan) {
[self.voiceRecorderView setCancelText:WSCancelLabelTextStart];
if (!audioRecorder.recording)
{
[self startRecording];
}
cancelflag = NO;
}
else if (gesture.state == UIGestureRecognizerStateChanged)
{
CGPoint touchPoint = [gesture locationInView:self.voiceRecorderView];
if (!CGRectContainsPoint(self.voiceRecorderView.recordButton.frame, touchPoint )) {
cancelflag = YES;
[self.voiceRecorderView.recordButton setImage:[UIImage imageNamed:kWSGreyDotXLarge] forState:UIControlStateNormal];
[self.voiceRecorderView setCancelText:WSCancelLabelTextCancelling];
}
else {
cancelflag = NO;
[self.voiceRecorderView.recordButton setImage:[UIImage imageNamed:kWSPinkDotXLarge] forState:UIControlStateNormal];
[self.voiceRecorderView setCancelText:WSCancelLabelTextStart];
}
}
else if (gesture.state == UIGestureRecognizerStateEnded) {
[self stopRecording];
if(!cancelflag)
{
[self sendRecording:self.recordingURL];
}
else {
[self.voiceRecorderView setCancelText:WSCancelLabelTextCancelled];
}
[self.voiceRecorderView resetView];
}
}

The progress not displaying in UITable cell in ios 7

The progress not displaying in UITableCell in ios 7.
This code work on ios 6.1.3 but not work in ios 7...
#
This code work on ios 6.1.3
#
-(void)updateFileProgress:(NSNotification *)notification {
NSArray *indexAndProgress = [notification object];
NSString *file = [indexAndProgress objectAtIndex:0];
float progress = [[indexAndProgress objectAtIndex:1] floatValue];
int index = [[Data sharedData] indexOfBookFileName:file];
[[Data sharedData] persentDone:[NSNumber numberWithFloat:progress] inBookIndex:[NSNumber numberWithInt:index]];
if(!searching) {
int bookIndex = index;
int row = -1;
if(iPad) row = (bookIndex / (orientation ? 5:6));
else row = (bookIndex / (orientation ? 3:4));
NSArray *indexPathes = [booksTable indexPathsForVisibleRows];
UIButton *fbutton = nil;
for(NSIndexPath *indexPath in indexPathes)
{
if(indexPath.row == row)
{
UITableViewCell *cell = [booksTable cellForRowAtIndexPath:indexPath];
for (UIButton *button in [cell subviews])
{
if([button isKindOfClass:[UIButton class]] && button.tag == bookIndex)
{
fbutton = button;
break;
}
}
break;
}
}
NSLog(#"fbutton = %#", fbutton);
if(fbutton) {
UIProgressView *currentProgressView = (UIProgressView *)[fbutton viewWithTag:tPROGRESS_VIEW];
if(currentProgressView)
{
currentProgressView.progress = progress;
} else {
currentProgressView = [[[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault] autorelease];
currentProgressView.frame = CGRectMake(5 , fbutton.frame.size.height - 10, fbutton.frame.size.width-10, 6);
currentProgressView.tag = tPROGRESS_VIEW;
currentProgressView.progress = progress;
NSLog(#"add subview to button");
[fbutton addSubview:currentProgressView];
}
if(progress == 0 || progress >= 1 || progress < 0)
{
[currentProgressView removeFromSuperview];
[[Data sharedData] performSelector:#selector(refreshBookList) withObject:nil afterDelay:1];
[[Data sharedData] refreshBookList];
}
}
}
}
In IOS 7 I'l create new UITable structure and may be UIButton *button in [cell subviews] - not return button and next code button isKindOfClass:[UIButton class]] - not work.
Then I change code to this:
for (UIButton *button in [[cell.subviews lastObject] subviews]) {
if([button isKindOfClass:[UIButton class]] && button.tag == bookIndex) {
fbutton = button;
break;
}
}
Then I change code to this:
for (UIButton *button in [[cell.subviews lastObject] subviews]) {
if([button isKindOfClass:[UIButton class]] && button.tag == bookIndex) {
fbutton = button;
break;
}
}
This code return UICellButton but UIProgress not dispaying in table cell.
BringToFront not help.
Help me.

Remove Keyboard Form toolbar on ios7 leaves a blur behind

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()
}
}

how to remove prev next button from virtual keyboard IOS

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)