swift Multiple video playing in UITableViewCell depends on Scroll - ios

Hi I am trying to make some application.
that is this application (i can't upload video in stackoverflow.. so i linked my blog and uploaded video)
http://blog.naver.com/cooksunghun/220488172371
like this application.
there are multiple video in tableview.
but play video is in only one talbleViewCell
I tried and i made tableViewCell and embed video. but i can't function that play only one part depends on scroll... (i am new about progmraming T_T)
I tried with scrollViewDidScroll and VisibleCells
func scrollViewDidScroll(scrollView: UIScrollView) {
let cell = VideoCell()
let visibleCell = tableView.visibleCells
var count = visibleCell[0]
switch count {
case visibleCell[0] : cell.playVideo()
case visibleCell[1] : print("test2")
case visibleCell[2] : print("test3")
case visibleCell[3] : print("test4")
default : print("testDefault")
}
}
i hope someone give idea. Thanks you!
(sorry for bad english)
i am waiting your idea!

Maybe it's too late but you are on wrong way. You don't need UIScrollViewDelegate methods, only thing you need this methods from UITableViewDelegate;
- tableView:willDisplayCell:forRowAtIndexPath:
For what? According to Apple docs;
A table view sends this message to its delegate just before it uses
cell to draw a row, thereby permitting the delegate to customize the
cell object before it is displayed. This method gives the delegate a
chance to override state-based properties set earlier by the table
view, such as selection and background color. After the delegate
returns, the table view sets only the alpha and frame properties, and
then only when animating rows as they slide in or out.
So, according to scroll direction while your next cell will prepare to display, this method firing and you need to prepare your video content to play in this method.
- tableView:didEndDisplayingCell:forRowAtIndexPath:
For what? According to Apple docs;
Use this method to detect when a cell is removed from a table view, as
opposed to monitoring the view itself to see when it appears or
disappears.
So, according to scroll direction, while your cell which one is last seen will preparing to destroy. Meanwhile, your next cell will be preparing to display. You need to prepare to stop your video content here. You didn't give any information about your video content class which could be MPMoviePlayerController or AVFoundation so search for how to prepare your video content to stop and play.

Related

Auto scroll on table view cell to the next row does not work Swift

i just develop a music player streaming app recently probably using avplayer. The situation is, i have a table view with list of songs which auto play feature, where, First, user need to choose song from table view, whenever the current song end, the table view will autoscroll and highlight to the next cell. Here how i did it inside AVPlayerItemDidPlayToEndTime delegate function:
let indexPosition = IndexPath(row: MusicPlayerManager.shared.latestIndex, section: 0)
self.tableView.scrollToRow(at: indexPosition, at: .none, animated: true)
self.tableView.selectRow(at: indexPosition, animated: true, scrollPosition: .none)
where MusicPlayerManager.shared.latestIndex is the current cell index. And everything work well accordingly.
For your information, i have declare AVPlayer as global variable (singleton) to allow the music playing in any page (viewcontroller) as below:
final class MusicPlayerManager {
static let shared = MusicPlayerManager()
private init() { }
var player: AVPlayer!
var latestIndex = 0
var playlistFrame = Playlist()
}
All still work well, where, i can pause, stop, play , auto play and others.
The situation and the problem occur when the songs is currently playing then i navigate to other ViewControllers, and go back to my MusicViewController (main vc), then, the auto scroll and highlight (select row) didnt work anymore. The player is still goes as usual without problems. The problem only on table view MusicViewController is my main viewcontroller where all the tableview and the music player are there. If i stay on the MusicViewController page without navigate to other controller, everything goes well.
To make the autoscroll work, i need to start over the flow, where i need to choose the list of music from the table view.
i navigate to other page using segue, where each time i going back to MusicViewController page, viewdidload() being called
i load all list music into tableview inside viewdidload(). Already try inside viewdidappear, but still not work
sorry for my bad english. Because english is not my native language. Thanks
i need to know atleast the cause of this behaviour. I try manually execute function scrollToRow and selectRow using button, it works well. It just not work automatically on code.

Customisable tableview cell swipe to stop on full expansion?

Is there any way to easily achieve the results in the pictures below (maybe by using MGSwipeTableCell or SwipeCellKit or any other pod you know of). I'm pretty sure you can't do that using the default iOS UIKit.
There are 2 things here to consider:
1) The table view cell swipe actions, should be completely customisable (putting an UIView there, so you can put anything you want inside the UIView) or at least, get closer to the screenshot, using 1 and then 5 buttons (therefore, different swipe-actions for smallswipe and fullswipe) ?
2) The tableview cell swipe action, must first (small-swipe) only show the "alarm' icon like in the first picture, and if you click on it, or swipe even further it should look like in the second picture, and most importantly, stay like that, no auto-unswiping (no action to be done, except waiting for input from user, to either select another cell, or any of the buttons there).
I'm not asking for a complete solution, I just want to know if it's possible and relatively easy to do, so I won't waste weeks in order to try to achieve this and find out in the end that it's not possible.
SmallSwipe
FullSwipeOrClick
I think in you tableCell, you can add view to contentView, that will be fill all cell and drag it via UIPanGestureRecognizer. Your action views will be under scrollable view. Something like this:
class SwipableTableViewCell: UITableViewCell {
#IBOutlet var actionView: UIView // under mainView
#IBOutlet var mainView: UIView // take whole place of contentView
#IBOutlet var panGesture: UIPanGestureRecognizer
#IBAction func panAction(_ sender: UIPanGestureRecognizer) {
// drag main view left or right and logic of auto swiping
}
}
I really don't know if you can make a small and full swipe native. The method for swipe for iOS 11 is tableView(_:trailingSwipeActionsConfigurationForRowAt:).
From there, I know there is performFirsActionWithFullSwipe, that doesn't allow full swipe on the first time. I think you can play with this two. In configuration you can add UIContextualAction that has an action, image and even background color that you can set.
I hope it helps.

swipe between views using scrollview - swift

in viewDidLoad :
viewPager.dataSource = self
--
extension DetailsViewController:ViewPagerDataSource{
func numberOfItems(_ viewPager:ViewPager) -> Int {
return dict!.count
}
func viewAtIndex(_ viewPager:ViewPager, index:Int, view:UIView?) -> UIView {
func viewAtIndex(_ viewPager:ViewPager, index:Int, view:UIView?) -> UIView {
return view
the result is slow , it does not show the animation of transition maybe cuz I return the scrollview view not normal view , and when I swipe to left it shows nothing (swipe backwards) , is there anything better to implement ?
thanks for help.
Your question isn't very clear, and then you post a BUNCH of code, including code that's irrelevant to your question. You should only post the parts that directly relate to your question.
It looks like what you want is a UIPageViewController. That manages an array of view controllers, each of which holds the contents of one page. You can either user it with a page curl animation like iBooks, or a scrolling mode. You want the scrolling mode.
If you search in the Xcode help (or online, it looks like the link to download the app isn't in Xcode 8) on "PhotoScroller" You'll find a demo app that illustrates how it works.
That app is written in Objective-C, but it will at least show you the UI it offers.
In order to use a UIPageViewController you'll have to restructure your detail view controller to manage an array of child view controllers instead of only using a single view controller.
If you want side scrolling AND up and down scrolling among a grid of tiles then you want a collection view instead, but that's more work to set up.

iOS table cells with fixed images

I'm developing an ios app and am trying to achieve an effect in a tableview like the following website: http://www.poormet.com/
There is a couple of ways I have thought about this. I know you can set the background of the tableview which remains fixed and then you could possibly swap the images as the text box covers the image. This is limited though as you can only have one image on the screen at a time which is not what I'm after.
I also thought about pushing the image down for each cell as the cell moves up, but for this case I couldn't set the frames position in the scrollViewDidScroll method(which I used to obtain the frames actual position in the tableview).
I was also wondering if there was anything similar in ios to what you have with div's in html where you can specify an image to be fixed.
How would I go about doing this? If you guys need any more information let me know, I'm new to posting on this site.
Thanks.
I think you should be able to do this through scrollViewDidScroll. I'm guessing you already have subclassed UITableViewCell and made your own, so heres a thought:
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
for(UITableViewCell *cell in [yourTableView visibleCells])
{
//I haven't tried this `convertRect` method, and the views might be in the
//wrong order, but I'm sure you'll figure it out. It should solve this.
CGRect position = [yourTableView convertRect:cell.frame toView:self.view]
[((YourCustomCell*)cell) updateImage:position];
}
}
Then in your custom cell class, add a method named -(void)updateImage:(CGRect)position; which will now contain the location of the cell, and you can move the image whatever way you want, as I'm guessing you already have a method for. I.E:
-(void)updateImage:(CGRect)position
{
//change the location of the image inside self.imageView here
}

UIRefreshControl for "Pull Up" to refresh?

How do I add UIRefreshControl to bottom of a UIColloectionView? That means how does it work when It comes to Scroll up (to see old data or something)?
You can't use UIRefreshControl to do that, but if you're ok with a simpler solution, you could just set up your collection view to automatically load more data when you scroll to the bottom. (Incidentally, this is a far more common user interface ... the pull up to refresh is not common, but automatically retrieving more data when you hit the bottom is.)
The most primitive rendition of that would be to respond to the UIScrollViewDelegate method and determine if you've scrolled to the bottom of the collection view (which is, itself, a subclass of the UIScrollView):
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if ((scrollView.contentOffset.y + scrollView.frame.size.height) >= scrollView.contentSize.height)
{
if (!self.isLoadingMoreData)
{
self.loadingMoreData = YES;
// proceed with the loading of more data
}
}
}
Even better, if you have more data to load, show a cell at the bottom, that says "please wait, loading more data", perhaps with a UIActivityIndicatorView. For example, if you have more data to load, add a section to the end with this one cell. If you format this additional cell properly (e.g. a single cell that goes all the way across the collection view), it could definitely render the effect you're looking for.
Here is a CCBottomRefreshControl category for UIScrollView class (parent of UICollectionView class) that implements bottomRefreshControl property. It's compatible with both iOS 6 and 7 native refresh controls.
You can't. You can't really customise UIRefreshControl at all.

Resources