Pull to refresh for simple UIView - ios

Can anybody advice how to implement pull to refresh functionality on iOS for a simple UIView without UIScrollView?
I've tried to use UIRefreshControll, but it should be added either to UITableView or UIScrollView, but I have just a UIView. When I add UIRefreshControll to UIView my App is crashing.
I do not want to add UIScrollView to the existing layout, because my screen is splitted to two section: top part is UIView and bottom part is UITableView. If I add UIScrollView to the top part I'll have 2 UIScrollView on the same screen, what I think is not good. But I need pull to refresh for the whole screen, to that user can refresh both top and bottom part of the screen.
I'd appreciate any ideas.
My code example:
public override ViewDidLoad()
{
var refresh = new UIRefreshControl();
MyView.Add(refresh); // crash here
//MyView.AddSubview(refresh); // such option also causes crash
}

It can be done in 2 ways :-
(1.) You need to add pan gesture recogniser interactively to UIView and needs to adjust y position of both UIView and UITableview according to pan movement downwards and after some threshold value you have to move UIView and UITableView back to its default position.
NOTE:- In this case, you have to add circular loader animation also, same as how it comes in UIRefreshControl. This will also be a part of interactive pan gesture.
(2.) You can add UIView as a section header of UITableView.

Related

iOS - Detect panGesture on edge of screen to open side menu + UICollectionView with horizontal scrolling

I just have an UICollectionView inside my UIViewController.
I am using SWRevealViewController to open left/right side menu. I can set its panGestureRecognizer to provide full screen panning.
view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
The following method will provide a panGestureRecognizer suitable
to be added to any view in order to perform usual drag and swipe
gestures to reveal the rear views. This is usually added to the top
bar of a front controller, but it can be added to your
frontViewController view or to the reveal controller view to provide
full screen panning. By default, the panGestureRecognizer is added
to the view containing the front controller view. To keep this default
behavior you still need to call this method, just don't add it to
any of your views. The default setup allows you to dissable user
interactions on your controller views without affecting the
recognizer.
My issue is that on a specific cell of my UICollectionView I don't have any spacing on the edges. The cellWidth = collectionView.bounds.size.width AND this cell contains an UICollectionView with horizontal scrolling.
Instead of opening my left/right menu, it just scroll horizontally my UICollectionView.
I would like to handle this scenario:
1: if the panGesture is located within the UICollectionViewCell containing the UICollectionView with horizontal scrolling.
2: detect the gesture location on the horizontal axis, and if it is on the edge of the screen, don't trigger the horizontal scrolling of the UICollectionView but trigger the panGesture to open the menu.
After reading a lot of articles and the official documentation I found this UIScreenEdgePanGestureRecognizer.
But also that this logic should be done by overriding the method shouldReceiveTouch, am I right?
Any hint on how I should implement this ?
EDIT:
After reading the question suggested in the comment, this is what I tried, but it's not working.
let edgePanGesture = UIScreenEdgePanGestureRecognizer()
collectionView.panGestureRecognizer.require(toFail: edgePanGesture)
I set this in my cell containing the horizontal collectionView but it's not working.
I might be missing something, any help?

Which the better way to make carousel view in swift with open - animation (expanding)?

I need to make carousel view in swift with "opening-animation".
First of all, I have created scroll view, after that have created subViews with my customView, maked my scrollView paged-enabled, and it's okay, but I need to make it expanding by swipe gesture. I added animation, but this view can't be higher than scrollView height, so I need to make this width and height (after gesture) like viewController's view height and width. And, it's the problem.
What's better way to do this?
Example screen:
BeforeGesture
Second example screen: after up-swipe gesture
I think you will need to handle it using the UIPanGestureRecognizer gesture which will give you the better control on all the different states of pan (drag began, drag ended). In your drag ended state you can handle the logic of increasing the height of scrollview and after that add the animation to show the expanded view with animation effect.
Let me know if you need any further help.

Move subview inside UICollectionViewCell upon touch

I have a issue in moving the frames inside UICollectionViewCell.
I have a small dot(made up of UIView) present inside the UICollectionViewCell and I have set the UIPanGestureRecognizer on my UICollectionView. Upon panning if the dot is being touched and moved, I want to move the dot inside the cell. I am able to change the frame of dot correctly(as shown by debugger), but the same is not getting reflected on the device screen. Please can someone suggest me what could possibly be wrong. I expect that somehow I have to refresh the views so that same can be reflected on device screen.
Some points if necessary:
1) I have subclassed UICollectionViewFlowLayout and using my own layout.
2) I have kept the UIPanGestureRecognizer on the entire UICollectionView and not in each UICollectionViewCell. I do not want to keep the UIPanGestureRecognizer in each cell. So please do not suggest me that.
edit: 3) The project is not using autolayout.
Yes, I have tried searching on this, but I am unable to find any suitable solution.

Scroll View doesn't scroll when touching and holding then swiping

I have UIScrollView with other UIView elements inside. My other UIView elements are mostly segmented controls. If I click on a UISegmentedControl and hold for a second and then try to scroll, then no scrolling happens. I can only scroll when my finger touches and swipes immediately. I checked other iOS applications such as mail. The behavior was that you touch and hold on a mail, then it's highlighted, but as soon as finger moves away, the scrolling happens and highlighting is undone. How can I implement this behavior?
The issue was the property of UIScrollView. The property canCancelContentTouches was set to NO. Because of that, touch events were handled by subviews of scroll view and swiping didn't cause scrolling.
You can follow one of these steps:
If you are using UISegmentedControl over you UIScrollView, instead of that, add the UISegmentedControl over your controller's view.
If you want to use UISegmentedControl over your scrollView, then you have to create a custom scrollView by creating a subclass of UIScrollView and use an image view instead of UISegmentedControl adding the labels which can act as the segments. This is because your UISegmentControl itself is a touch handler and it breaks the UIResponder chain. So, the scrolling might face issues during the touch events.
Please let me know if any of these works. Thanks :)

Drawing in screen with finger in UITableView

I am following this excellent small tutorial about drawing on screen in the layer of a UIView (subclass).
http://spritebandits.wordpress.com/
It just works.
There is just one thing. I placed this view as subview of a UITableViewCell which, naturally, is displayed as part of a UITableView.
I guess I would have the same issue when I would place it within an UIScrollView. (UITableView inherits from UIScrollView anyway)
Touches are triggered by my painting view as long as their related movement is horizontal. As soon as I move the finger kinda vertical, even partly, then the UITableView takes over and scrolls the table.
Is there any proper way of stopping the Table to taike control of the touches while the touch is actually within my view?
If it is of importance: I am using storyboard. The cell is a prototype cell with its own subclass of UITableViewCell.
I've implemented this using the same class "Canvas" you're saying and also inside a UITableViewCell. But I didn't use the entire cell for drawing, only a UIView inside of the UITableView as a subview.
I reached the whole user experience by activating and deactivating the UITableView scrolling when that UIView (subview of the cell where I allow the drawing) fires touchesBegan or touchesEnded. So when they touch/move inside the UIView, they're drawing. When it's outside, they're scrolling. So they can't scroll on the UIView because they will be drawing.
The problem in your case is that since the whole cell is the view for drawing, the user cannot scroll in this concrete cell because it's the drawing one.
Hope this will help.
I dont have an answer for that. But there is essentially a work around.
You could get the user in to a drawing mode, where the scrolling for a UItableviewcell is disabled and then
once the user is done with drawing, you could enable scrolling again.
Inclusion of a button anywhere on the screen would help you switch modes.

Resources