We are integrating a third party offer wall into our iOS phonegap app.
When we show the offerwall it gets added to the standard phonegap viewcontroller and shows over the top of our webview.
The problem with it is that people can drag the view all over the place so instead of just scrolling up and down in place. Which gives the effect show in the screenshot below:
What we want to achieve is being able to anchor this view so it can't be dragged around the app and can only be scrolled vertically.
In the integration code we have access to a UIView for the offerwall and the ViewController of the main app.
The offerwall is provided as a library so I don't have access to any of its code and can only deal with the UIView returned and the UIViewController I add it to. Other apps have managed to implement the view without horizontal scrolling
We are looking for code to apply to either the UIView or ViewController to prevent this.
Thanks
The offerwall view probably contains a UIScrollView that holds the actual content. You could try looping through all subviews and turn off scrolling on the first scroll view it finds:
for (UIView *view in offerwall.subviews) {
if ([view isKindOfClass:[UIScrollView class]]) {
UIScrollView *scrollView = (UIScrollView*)view;
scrollView.scrollEnabled = NO;
return;
}
}
This is definitely hacky, but if you don't have access to anything else from their code it might be your only option.
In the end the solution was quite simple. Turns out the offerwall was a UIWebView and in testing mode the offerwall page was rendering some elements that were overflowing the page hence the horizontal scrolling. In production mode the problem goes away
Related
i am having some very strange issue. Basically i am implementing a drag and drop view with a snap to the horizontal 1D grid. Well, so when i drag a view and its center coordinate X is bigger or smaller then a different view, the non-dragged view should be animated to the left or right of its original position.
This works fine most of the time. But in some special cases its not working. In some situations specific situations the view does not receive any gesture callbacks anymore. I can reproduce this issue and have found out that when i remove the code that applies the animation, everything its working fine.
Basically this is the code that is called when the dragged view is at a position where the view below should be moved to the left or right
/**
* Animate element to its saved position
*/
- (void)switchElement:(unsigned int)draggedIndex with:(unsigned int)otherIndex
{
// first animate
UIView *view = views[draggedIndex];
UIView *otherView = views[otherIndex];
// IF I COMMENT THIS OUT, EVERYTHING WORKS FINE
otherView.frame = [self getImageRectForIndex:draggedIndex];
// now switch internally
if(draggedIndex != otherIndex)
{
// switch views
views[draggedIndex] = otherView;
views[otherIndex] = view;
}
}
Any idea if there is something to have in mind if i animate UIViews and have gesture recognizers attached to them?
If somebody is willing, i can paste the whole class here to test it.
SOLUTION
I am having some "highlight" views in my design. And i have moved the relevant views behind those transparent background views by accident. So now i am not using addSubview: but insertSubview:atIndex: instead.
But marking #Anthonin C. answers as the right one. Because it pointed me in the correct direction (I found it out by overriding the hitTest: method)
Would you please track the otherView.bounds property to verify that your touch isn't out of bounds. I faced this issue recently and Apple documentation provide solution here : Delivering touch events to a view outside the bounds of its parent view
Sorry, I don't have enough reputation to comment your answer.
I am developping an iPad app using Xamaring that has several views in the storyboard (UIView and UITableView). My users want to zoom on usual pages (as they are used to in a web browser or so).
So, having read about UIScrollView, I simply tried to put my page views embedded within a UIScrollView, but I can neither scroll nor pinch-zoom: nothing happens.
As for the setup: in the StoryBoard, I add a UIScrollView to the UIViewController which fills the parent. I then add content to the UIScrollView, which I want to be zoomable (e.g. for people with poor sight).
So the question is quite simple: how can I get a view fitting within its original parent but that can be zoomed onto ?
Thanks in advance!
I have never done this myself, so I dont know if this is all it takes. But have you added the max- and min-scroll and all that?
scrollView.MaximumZoomScale = 3f;
scrollView.MinimumZoomScale = .1f;
scrollView.ViewForZoomingInScrollView += (UIScrollView sv) => { return imageView; };
(in your case i guess it needs to return the view);
If that doesent do the trick, take a look at "Scrolling and zooming a view hierarchy on this page: http://www.raywenderlich.com/10518/how-to-use-uiscrollview-to-scroll-and-zoom-content
I am working registration form in iOS application. There several textfields such as name,email,city etc. when the textfield started editing cursor appearing like animated. Cursor slowly coming from top to down after typing the letter its moving from left to right slowly.I need to stop this unwanted animation. I am using TPKeyboardAvoiding scrollview to scroll the view when keyboard popup. I checked it without TPKeyboardAvoiding but same thing happening.
I encountered same issue, after debugging I found that this weird animation is happening because of
- (void)TPKeyboardAvoiding_keyboardWillShow:(NSNotification*)notification {
//...
[self layoutIfNeeded];
//...
}
- (void)TPKeyboardAvoiding_keyboardWillHide:(NSNotification*)notification {
//...
[self layoutIfNeeded];
//...
}
I am able to fix this issue by removing [self layoutIfNeeded]; method call. I don't know if this solution affects anything else.
I suspect the animation comes from the TPKeyboardAvoiding library. I also have the same screen in my app (Registration) and use the same library. However I put my textfields inside a custom UITableViewCell and have a UITableView for the registration. This way there is less code and its cleaner. I disable scrolling on the UITableView so that the UIScrollView will receive the touches correctly.
I'd suggest doing it that way.
Call superview.layoutIfNeeded() (or self.view.layoutIfNeeded(), depending on your code context) before you begin changing any animatable properties in the view. This allows the superview to finish its own layout changes (if any) before you make your own layout changes and commit your animations. (This may be difficult to track down if an external library is applying its own animations.)
I've been researching how to use a UIWebView embedded in a UIScrollView for a while now and cant seem to find an easy fix to my problem. I'm using a UIWebView because a UITextView, although allowing hyperlinks, does not allow you to change the link color from the standard blue apple sets.
But using a UIWebView introduces another problem: It blocks the UIScrollView it is embedded in from handling scroll events because a UIWebView handles these events within its own private implementation.
Although this allows me to use its embedded links, the UIWebView absorbs the touch events which doesn't allow me to scroll up/down when dragging within the UIWebView itself. I worked around this problem by placing a transparent UIView overlay exactly over the UIWebView, intercepting the touch events that it receives, and resigning it as first responder so that the UIScrollView that they are both subviews of can handle the scrolling appropriately.
Now, however, I can't seem to think of solution to the new problem this introduces: I can't click on the links within my UIWebView that is right under the UIView Overlay.
What is the best way to forward touch events to a UIWebView that is right underneath my transparent UIView in order to trigger my UIWebView's delegate method 'webView:shouldStartLoadWithRequest:navigationType:' for tapping on links?
FYI from UIWebView API doc:
Important: You should not embed UIWebView or UITableView objects in UIScrollView objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled.
Back to the question,
UIWebView has property called scrollView, try doing:
webView.scrollView.scrollEnable = NO;
In iOS 6 beta 4 and iOS 5.1.1 I have had left/right swipes allowing users to swipe between different QLPreviewControllers, hosted in a UIViewController.
In the released version of iOS 6 the swipes are now completely ignored.
Attempted to put a UIView as a subview of the preview controller in an attempt to get the view hosting the preview controller to intercept the swipes before the preview controller has a chance to swallow them, but these are never triggered.
Any one seen this or know of a work around.
Thanks,
I had the same problem but with UITapGestureRecognizer not working on QLPreviewController. In iOS 6 that thing is like a black hole for UIGestureRecognizer objects...nothing makes it out of there!
However I did find a workaround. I am subclassing QLPreviewController, so in my subclass I abused the (relatively) new viewWillLayoutSubviews method and added the following snippet:
UIView *overlay = [[UIView alloc] initWithFrame:self.view.frame];
overlay.backgroundColor = [UIColor whiteColor];
overlay.alpha = .002f;
for (UIView *v in self.view.subviews)
{
[v addSubview:overlay];
}
[overlay release];
It may be overkill, but I basically went into the all of the quick look subviews and added a view to them that WOULD accept the gesture. I went with .002 alpha because making it lower would cause the gestures to be ignored again.
I have also found that using the same code, UIGestureRecognizers have stopped working under iOS 6. But it is not that totally broken. Apple Development Sample project "SimpleGestureRecognizers" still functions. After comparing the code, I found that explicitly "addGestureRecognizer" resolved the problem (besides all the other steps you used to do under IB). Assuming your one of your IBOutlets names leftSwiftRecognizer, you could do:
- (void)viewDidLoad
{
[super viewDidLoad];
....
// swipe recognizer
[self.view addGestureRecognizer:self.leftSwiftRecognizer];
}
Your attempted solution was close, but probably backwards from what you should have done. Instead of adding another view as a subview of the preview controller, add the preview controller as a subview of the UIView.
Subview the preview controller inside a standard UIView. Then, reassign your gestures to the UIView's gestureRecognizers collection, removing them from the QLPreviewController's collection.
Not sure why this changed, but I had the same issue with my app, except for me it was the UITableView that wasn't scrolling anymore.