I have a Flatlist element that renders a collection of Views that could be Images or Videos, similar to a Facebook feed. Is there any way to detect when a View will disappear from screen so I could stop automatic playback of video elements?
Currently my Flatlist component has a scrollHandler attached that detects the offset of the content and calculates the view number.
scrollHandler(event){
let postHeight = 200;
var currentOffset = Number(event.nativeEvent.contentOffset.y);
this.offsetActual=currentOffset;
this.velOffset=currentOffset-this.prevOffset;
this.prevOffset=currentOffset;
let postNumber=(currentOffset/postHeight);
// Any additional logic
}
Could there be something like UITableViewCell will disappear but for the Flatlist elements? Or any other handler where I could attach "will disappear" logic?
Thank you for your help!
You need to make use of onViewableItemsChanged prop. This way you'll know which items are visible at the moment.
Related
hope everyone is doing good. I have a small problem I can't find any solution. I have a scrollView where I activated isPagingEnabled on it. The scrollview contains multiple images the size of the scrollView.frame.width. My problem is I am trying to find a solution where when the scrollView changes the "page of the picture" I am notified. I tried different methods. I have tried with delegate scrollViewWillEnd and both DidEnd. My method was this
var pagePositionOfScrollView = Int(scrollView.contentOffset.x/self.scrollView.frame.width)
var positionActualIncremented = self.positionActual + 1;
print("positionofscroll view page \(positionOfScrollView)")
print("position actual \(positionActualIncremented)")
I have found that with this implementation there is a problem, the user could drag only to half of it, the page will still scroll to the next one because of isPagingEnabled, but the ending position would be still on the same page and so the pagePositionOfScrollView will be the same. As well isPagingEnabled offers the possibility that if the user slides with velocity the page is changed, but the final scrollView.contentOffset.x still gonna be on the same page, not on the next.
Does anybody have any ideas?
I have a custom view covering entire screen in iPod touch. I need to put add another view in this which will initially be hidden but will come on screen when view is scrolled down. I hav achieved this but not I can scroll my view to upside also. I so not want user to pull up the custom view. I just want a pull down feature and no pull up.
When someone pull down I am bringing the view to original position programatically. So, when user pull down they can see some information for 5 secs and then view is back to original position.
Hoe can I restrict my UIScrollView from being scrolled towards up on manual interaction?
I did this by following code. Its working now.
(void)scrollViewDidScroll:(UIScrollView *)iScrollView {
// Refrain the view from scrolling up
if (iScrollView.contentOffset.y > 0.0) {
iScrollView.contentOffset = CGPointZero;
}
}
I need to build a scroll view (with 10 items for example) that can be continuously scrolled (with paging enabled). In other words as you keep scrolling to the right, you see the item you started with once to get to the end, and it just keeps looping.
I'm looking for recommendations on how to a approach this. I will be receiving an array of images. I can lay them out next to each other no problem. My main concern is how/when to move the images so they keep appearing in a loop as you scroll. Thanks!
Append the first picture as the last picture. Just as you move further right from the last picture, jump to the first.
And vice versa of course.
Use -(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView; delegate to know when someone's moving through your scroll view.
When you get to the last page you need to move the first image view in the scroll view to the end. ie:
for(UIImageView *image in myscrollview){
if(image.frame.origin.x == 0){
// move to the end...
}
else{
// move your image a scroll view's width to the left...
}
}
obviously it will be much more complicated than this, you will have to work out which way the user is scrolling and sort it out like that, but this gives you a basis to start with. :)
Im using NSThead and have a loading screen whilst im downloading images form the web to display, whist this is happening, could i stop the UI touch being registered? I have buttons on that view and when the loading screen is up, its basicllya text label which has a slightly transparent background. but if someone clicks on it, it registers the back ground buttons being clicked so i want to avoid that.
I recommend to use a UIAlertView for this.
Override the buttons and provide your own "HideIt" handler wich finally call Dismiss...
UIAlterView is somehow a UIView so you can change it's look.
And it blocks the underlying UI without any extra code.
Also possible - Create a (somehow transparent) UIView which covers your View.
You can place a text and / or a UIActivity... on it to show a loading animation.
When loading starts show this thing - when done hide id.
If you want to update this view (Progress indicator / text) be sure to run the updates on the MainThread.
Manfred
I would like to put thumbnails in the toolbar like the Photos app. Like the screenshot on the left:
(source: apple.com)
Is there is a built-in control to do this, or do I have to implement it from scratch?
If the answer is from scratch, any tips?
This would be a control you'd have to write yourself. I'm not what the best approach would be, but I think I'd go with subclassing a UISlider, drawing the array of images next to each other to create the track, and then using the current image as the handle.
From scratch, is the answer, unfortunately.
You create a custom view and add your array of images as subviews using UIImageView objects incrementing your x position by the the thumbnail width you've determined to use.
Then override the touch events for you custom view. Determine which image view the touch is currently over in -touchesMoved and use Core Animation to animate the current view's scale making it larger than the rest. Add the custom view to your toolbar wrapping your custom view in a UIBarButtonItem using -initWithCustomView.
Remember to enable user interaction on your custom view or you won't receive any touch events. If you need help with the code, update your question with some code specific questions.
Should anyone still need it, I made an effort of coming up with ThumbnailPickerView - a simple UI control resembling Photos.app thumbnail slider.