Xamarin iOS How to Zoom on UIView and UITableView - ios

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

Related

UIGestureRecognizer not called after setting UIViews frame inside UIScrollView

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.

swipe navigation in objective-c

I want to add a second view controller to my project with a swipe navigation. Which is the easiest way?
As you can see in the picture I have these buttons in the first view, I want to add more. I also have a background picture which is not in the picture
(below), is it possible to keep it for both views? So when I swipe to the right the background should't move, only the buttons.
Also could you please explain to me how I should make it step by step, because I am new into coding and have almost no experience.
I think what you are trying to find is paging using UIScrollView. Check out this link.
Hope this helps you.
you can use the custom class called ADPageControl. Here is the reference link : https://www.cocoacontrols.com/controls/adcustompagecontrol.
And for that image you can set the common image below your container view. Please go through the link and try to implement it.
Basically you need a UIPageViewController But you have tweak a little bit. You can find a tutorial about that here
Few Points
Create PageViewController with buttons
Make each Page views background color as clear color so your background image will be shown all the time even when you swipe.
Please don't expect full code from SO
I think you trying implement something like ..look below code
its scrollview paging
// viewArray contains paging views
viewArray = [[NSMutableArray alloc] initWithObjects:self.viewOne, self.viewTwo, nil];
// adding all views as scrollview subview
for (int i = 0; i < viewArray.count; i++) {
self.scrollView.pagingEnabled = YES;
[self.scrollView addSubview:viewArray[i]];
}
// this time you need to set scrollview contentSize but in X axis ..
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * viewArray.count, self.scrollView.frame.size.height);
have a note: you can create views using storyboard or programmatically but must set the x position of views which you want to appear on swipe.. hope this helps.

UITableView scrolls down when contentInset is set and UITextField in tableViewHeader becomes active

Problem
I'm trying too make a custom search text field, added to a UITableViewController, always stick to the top of the page.
Like this:
Everything works fine, but when I tap the search text field to becomeFirstResponder the tableView strangely scrolls down.
I have discovered that this only happens when I manually setts the contentInset for the UITableView. (So that the tableview section headers don't hides behind the search view)
How I have built it
Layers:
TableView
UIView (as UITableView.tableViewHeaderView)
UIView (to update the frame when the user scrolling the tableView)
UITextField (for search input)
Code for fixing the search view frame when user scrolls:
var rect = frame
rect.origin.y = scrollView.contentOffset.y + 64
frame = rect
I may be doing everything stupid, but I would like to have the view stick to the top, because the user will use search more than other apps. Any ideas?
My app requires iOS 8 so I have not been available to test this on iOS 7. I can make a screen recording if that helps.
UPDATE
I've created an example project with the same objects I'm using in my main project.
https://www.dropbox.com/s/qdlx0milebbuf3p/Search%20bug%20Example.zip?dl=0
It's a UIKit bug. To fix this I've created a subclass for UITableView to NEVER change the content offset when isScrollEnabled is NO.
.h
#interface CUISearchTableView : UITableView
#end
.m
#import "CUISearchTableView.h"
#implementation CUISearchTableView
- (void)setContentOffset:(CGPoint)contentOffset {
if (self.isScrollEnabled) {
[super setContentOffset:contentOffset];
}
}
#end
I'm not sure you need to do all that. If you'd just use a UIViewController and add a UITableView to that, then you could place the UISearchView anywhere ( i.e., the top of the view ). You just need to make sure that the UISearchView is the top-most view ( bring subview to front ).
I get that you're using a UITableViewController, but if you want to use your own search view instead of the TableViewController+Search then this is your best bet. The only thing that would be necessary is adding the top content offset ( which you're already doing ). you could then just delete the CUISearchTableView.
Does this make sense or am I missing something?

How to create paging in iOS 7

I would like to kind of recreate the layout of the app I have pictures of below. There is a navigation bar at the top, with paged content in the middle. I have looked in to several ways of how to page content, including UIScrollViews, UIPageControl, and PageViewControllers, but I cant seem to quite be able to recreate this layout. Most tutorials that I find aren't updated for iOS7 either. All input is greatly appreciated.
Pictures:
Here's a few resources to help get you started.
Apple's documentation has a very good example of how to implement a paging scroll view using a UIPageViewController, see the Photo Scroller sample code here. I would suggest starting there.
I also have some code on github that modifies Apple's Photo Scroller example to load the UIPageViewController inside a UIViewController subclass.
This is a good tutorial by the Ray Wenderlich team on how to set up a paging scrollview: How To Use UIScrollView to Scroll and Zoom Content
I've also answered a few other questions about paging scroll views that you might find useful. See here, here, here and here.
Just have an int instance variable set initially to 0. If shouldn't matter if you use .xibs or storyboard, the concept remains the same. If you want to lay absolutely everything out in IB look here: How to add objects to a UIScrollView that extend beyond UIView from Storyboard?
To know when paging occurred use this:
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
CGFloat pageWidth = self.scrollview.bounds.size.width;
curIndex = floor((self.scrollview.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
if (curIndex == lastIndex) return;
lastIndex = curIndex;
//increment pager and do whatever else...
}
Here's a great tutorial on doing paged scrollView!
And BTW there's nothing special in iOS7 about this. At least nothing I can think of.

Stop UIView being dragged around screen

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

Resources