How to redraw view while scrolling? - iphone

I have a UIScrollView. This scroll view scrolls my custom GameView. When I send setNeedsDisplay to my GameView, it redraws and everything goes fine.
Except when I'm in the middle of scrolling GameView. It does not redraw until the scrolling has stopped.
Is there any way to circumvent this and just force the view during the scroll?
By the way, I already found these questions, but they didn't help:
UIScrollView pauses NSTimer until scrolling finishes
How do I get my UIView to redraw while the user is scrolling a UIScrollView

Try sending the view's layer displayIfNeeded immediately after setNeedsDisplay.

Related

Swift ScrollView what gesture is called when scrolling is ended if the contentSize is equal to the frameSize?

I can't figure out a solution. I have a UIScrollView, and on each scroll towards right, I will increase the contentSize of the scrollView and add a View at that place. The problem is I have managed to save the last content offset by delegation when scrollview start dragging but I don't understand which delegate method to use for measuring where the gesture stopped. If I use scrollViewDidEndDecelerating, will be called immediately after the scrollViewWillBeginDragging because the content is settled to the same size of the frame.
Does anybody have any solution on it?

How to implement an auto scroll view like notification center's stock ticker?

I want to implement a scroll view which looks like the stock ticker. It can respond slide or tap gesture.
How can I implement this? Please advise me. Thank you!
Use a NSTimer to reposition the contentOffset of your Scrollview.
Use the UIScrollViewDelegate to stop your animation while the user is dragging the scrollview.
Conceptually I'd setup an container UIScrollView with the contents of the scrolling area as subviews. To simulate a circular scroll I'd keep an array of the subviews. I'd add a view just off screen at the starting edge, and take away a view just off screen at ending edge.
UIScrollViewDelegate methods will be called when a person starts or stops dragging the view, which you can use to start and stop the animated scrolling. Other methods in this protocol can be used to reset the contents of the scrollview when the edge is reached, so more views can be added as needed.
I'd probably use a CADisplayLink to manually manage the animations. The method given to the CADisplayLink would update the scroll and manage adding and subtracting views to the edges. It would also stop scrolling based on a flag set by the UIScrollViewDelegate methods when the person is dragging the scroll.
Unless you jailbreak, you can't put custom views in Notification Centre.

UITableView Scroll w/ keyboardWillShow

I have uitableview scrolling upwards when keyboardWillShow event occurs. tableview is 320x148 and placed at the bottom of the uiview. When a user selects the first uitextfield, nsnotifcation is fired and moves the textfield accordingly.
My problem is, I have a label and logo in the background (uiview) that i want to see move upwards with the "event". I can do this with an animation, but it's not the desired effect.
My guess is to somehow make uiview move with uitableview somehow. Hope that makes sense.
Humm, i think you could put your UITableView inside a UIScrollView. When the UITableView scrolls, you could do the same to the UIScrollView behind..

UIScrollView freezes after using SetContentOffset or scrollRectToVisible

I have a UIScrollView with paging enabled and I want to be able to jump to pages further down the line rather then swiping through each one. I attempted to use both setContentOffset and scrollRectToVisible. They both scroll the view to the correct point but after scrolling animated or not the scrollview becomes frozen and unresponsive to any touches. I tried setting it to the first responder but it changed nothing. I have a button outside of the scroll view and it still functions fine after the setContentOffset. There are also buttons inside the scrollview and not only will the scrollview not respond to touch for dragging but the buttons will not recognize the touches either.
[mainScroll setContentOffset:CGPointMake(mainScroll.frame.size.width*4, 0.0) animated:YES];
tldr; I can scroll through the view fine, through all the pages but when I try and call a setContentOffset or a scrollRectToVisible I get 'frozen' after the move.
I figured it out, stupid mistake.
In my scrollViewDidScroll I had:
scrollView.userInteractionEnabled=NO;
and in my scrollViewDidEndDecelerating
scrollView.userInteractionEnabled=YES;
and in scrollViewDidEndDragging:willDecelerate
if(!decelerate){scrollView.userInteractionEnabled=YES;}
I had this to prevent button presses and any random things during a page transition. But when setContentOffset is called it only causes scrollViewDidScroll to be called and neither of the other two, so the UserInteraction was never set back to Enabled, but only when using setContentOffset.
Simple fix.

Second UIScrollView responding when using a UIScrollView

This is more of a check as I believe this is right but its a lot of work if I'm wrong.
I want to basically achieve fixed positioning with a scrollView. I want to have a list along the top that is always visible, scrolls horizontal only and then a scrollview beneath that to move around the information which scrolls both vertically and horizontally.
I figure I need to subclass UIScrollView and overwrite touchesBegan, touchesMoved and touchesEnded to send the touch to both UIScrollViews.
Is this right or off track?
Cheers
Overriding the touch events on a scroll view is probably not what you want to do. Instead you can simply use a single scroll view, and then in the parent view's -layoutSubviews or in the scroll view's delegate methods you can move the list so it's always at the same vertical position (use the scroll view's contentOffset property to determine where that should be). Both the delegate method and -layoutSubviews is called before the drawing actually occurs after the scroll view scrolls, so by always repositioning your view where you want it to be, it will appear to remain fixed to the user.