Keeping UIButton Stationary on Screen - objective-c

I have a UIButton on top of a UIWebView. The UIButton is supposed to look like it's native to the webpage. However, when I zoom in on the UIWebView, the button comes with it, obviously looking out of place. Is there a way to keep the button's position relative to the UIWebView rather than its position on screen?
Thanks for any help!

Not sure I've understood your problem, but here goes:
You've likely a view hierarchy like this:
View
UIWebView
UIButton
That is, your button was added as subview to the UIWebView. Since the UIWebView is also a UIScrollView you get the behavior you've observed. To fix it, make the button a sibling, not a child:
View
UIWebView
UIButton
It will still be drawn in front of your UIWebView if it was added after the UIWebView.

Related

UITableView inside UIScrollview Horizontal Paging Programatically

Good day,
I have a question about programmatically adding UITableView inside UIScrollView. The structure is like that:
UIView
UIScrollView
UIView(contentView)
UIImageView
UITableView
How can I add the UITableView programmatically inside UIScrollView so when I scroll horizontally to switch between UIImageView and UITableView. Note I am using Autolayout so I need to add constraints also. If it is going to be easier with storyboard please let me know how to do it with storyboard instead of programmatically
I used SwipeView it is pretty easy to use 5 minutes installation and did what I was looking for.

UITextField on UIScrollView (iOS 8.x only)

I have a view which is a subclass of UIScrollView and UITextField is on the UIScrollView. I'll refer the subclass of UIScrollView as 'CUScrollView'.
The purpose of CUScrollView is when user input a text, a button which has a title of the text will be added on the CUScrollView. The Offset of UITextField will be move at the right of the last added button.
This is how the CUScrollView look like.
Below iOS 8.x, it works perfectly; However it doesn't on iOS 8.x.
When the UITextField resigned first responder, the CUScrollView's contentSize is reset to CUScrollView's frame width.
I finally found a work around. I overrided the setContentSize: and set the contentSize to whatever I want.
Is it a bug? or some kind of auto layout mistake?
First of all don't mix auto layout with setting Frame's manually. If you perform like that then it will be the mistake in your autlayout.

UIScrollView on UIWebView and UITapGestureRecognizer conflicts

I have a UITapGestureRecognizer on a UIViewController, which has a UIScrollView and UIWebView inside. It recognizes the tap gesture only after I scroll the UIWebView. How could I prevent this ?. Basically I want the tap gesture to be detected, when I am not scrolling the web view. I looked around and the closest I found is this:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer*)otherGestureRecognizer {
return YES;
}
but not sure how can I use this to disable the tap while scrolling. Any idea?
Another thing I want to do is to disable the UITapGestureRecognizer, when a link on the UIWebView is clicked (shouldStartLoadWebRequest is called). I checked that the tap gesture recognizer is called, before the shouldStartLoadWebRequest is called. Basically when clicking on a link on a UIWebView, it shouldn't trigger the action invoked by the UITapGestureRecongnizer. Any idea on how to do this?
So Apple's documentation strongly recommends you don't nest a UIWebView inside a scroll view:
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.
It is possible on iOS 5 and above to get direct access to the underlying scroll view on a UIWebView (using the scrollView) property - playing around with this might help you.

How to synchronize scrolling of a NSScrollView and a WebView?

My app has two main views: a NSTextView subclass within a NSScrollView and a WebView. What the WebView displays is dependent on what the user enters into the text view - so I would like when the user scrolls either the text view or the web view the other scrolls proportionately to it.
I found this article which mentions how to do it with 2 scroll views. My problem is that WebKit doesn't seem to use normal Scroll views anywhere.
How should I implement this? What am I missing?
This is not a trivial problem to solve perfectly, as it's difficult to know whether the amount of text being edited in your text view corresponds to a similar amount of scrolling in the web view.
However, to answer your question about scroll views in WebView, they are used but as far as I know not documented extensively. You have to take advantage of the fact that you can obtain the scrollview being used, using public API, by asking the appropriate WebView subview for its "enclosingScrollView". Something like this works for me in a WebView where I know that there is only one frame:
[[[[myWebView mainFrame] frameView] documentView] enclosingScrollView];
If they are scrolling proportionately, probably the simplest solution would be to override touches events on your UIScrollview and impliment stringByEvaluatingJavaScriptFromString: on the UIWebView with (js) window.scroll(x,y). However, scrolling from the webView to the textview will require more work. The webView eats touches events, so you would need to
create a top level UIView or UIScroll view which captures the touches and sends them on to both the scrollView and the webView (via javascript) for ALL touches events, or
use a gesture recognizer to do the same.

Removing views from UIScrollView

I have two UIScrollViews that I move images between. The user can drag and forth between the scroll views. I am trying to animate the movement of the image from one scroll view to another. In -touchesMoved (handled in my UIViewController which has two custom UIScrollViews that intercept touch and sends to my UIViewController), I am trying to set the "center" of my UIImageView that is being moved. As it is moved, the image gets hidden behind the UIScrollView and not visible. How do I make it appear on top of the UIScrollView? I am able to handle the -touchesEnded properly by animating in the destination scroll view.
I am also confused about -convertPoint:fromView: usage in the iPhone Programming Guide (See Chapter 3, Event Handling). If the touch coordinates are in window coordinates, to change my view (UIImageView inside a UIScrollView which is inside a UIView and inside a window) center don't I have to use -convertPoint:toView:, i.e.,
imageView.center = [self.view.window convertPoint:currentTouchPosition toView:imageView];
What am I missing?
You can use the method - (void)bringSubviewToFront:(UIView *)view for making the image view the front most view.
Johan
It depends on how you structured your views. If both scrollviews and the imageview are at the same level, it should work. If the imageview is a subview of one of the scrollviews, you can try bringing the scrollview to the front. That way also the imageview will be drawn over the other scrollview.
Johan
I have a View Controller with two ScrollViews. Images are added as subviews. ScrollViews are already in the front. I tried bringing scrollview to the front and also imageview of the scrollview to the front. But somehow when i drag, the center of the image goes over my other scrollview2 which i also tried sending back. But does not seem to work. Here is what i do, in TouchesMove (inside a ViewController)
view= [[scrollView1 subviews] objectAtIndex:currentImageIndex];
[self.view bringSubviewToFront:scrollView1];
[scrollView1 bringSubviewToFront:view];
[self.view sendSubviewToBack:scrollView2];
scrollView1 and scrollView2 are two scrollviews that are part of the ViewController's view.
Does this make sense ?
thanks
mohan