Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigation to next/previous image breaks in iOS 14 #1

Open
nickdio opened this issue Oct 5, 2020 · 0 comments
Open

Navigation to next/previous image breaks in iOS 14 #1

nickdio opened this issue Oct 5, 2020 · 0 comments

Comments

@nickdio
Copy link

nickdio commented Oct 5, 2020

I have recently started building my own iOS app and trying to add Push Notifications particularly the Rich Push notifications.

I tried to use this example to show Carousel in Push Notification exactly as used in this project, it seems the Scrolling to next item is breaking in iOS 14.

I can see the scrollNextItem/scrollPreviousItem from the example are getting called but UICollectionView doesn't scroll to next/previous image using debugger.

Tested this with iOS 14.0.1 where the scroll to next/prev doesn't work, whereas this works fine with iOS 13.6.

Tried to add the UIPageControl and see if the scrolling works with ScrollView, but I couldn't see the PageControl itself in the UI.

var xPos: CGFloat
var yPos: CGFloat
let height: CGFloat = 30
let pageControl = UIPageControl()
pageControl.addTarget(self, action: #selector(self?.changePage(sender:)), for: .touchUpInside)
pageControl.hidesForSinglePage = true
pageControl.numberOfPages = 4
pageControl.currentPage = 0
xPos = (self.view.frame.width - width) / 2
yPos = (self.view.frame.height - height) - 10
pageControl.frame = CGRect(x: xPos, y: yPos, width: width, height: height)
self?.pageControl?.removeFromSuperview()
self?.pageControl = pageControl
Following are the attributes that I have for this view.

UIScrollView Attributes

And then using the scrollViewDidEndDecelerating delegate method.

func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
    pageControl?.currentPage = Int(scrollView.contentOffset.x) / Int(scrollView.frame.width)
    currentIndex = pageControl?.currentPage ?? 0
}

Changing based on the user action in func didReceive(_ response: UNNotificationResponse, completionHandler completion: @escaping (UNNotificationContentExtensionResponseOption) -> Void)

if response.actionIdentifier == "carousel.next" {
    if ((self.pageControl?.currentPage ?? 0) + 1) <  4) {
        self.pageControl?.currentPage += 1
        changePage(sender: self.pageControl)
    }
} else if response.actionIdentifier == "carousel.previous" {
    if ((self.pageControl?.currentPage ?? 0) - 1) <  4) {
        self.pageControl?.currentPage -= 1
        changePage(sender: self.pageControl)
    }
}

func changePage(sender: UIPageControl) {
    let pageCount = datahandler.carousalInfo?.data?.count ?? 0
    guard pageCount > 1 else {
        return
    }
    if sender.currentPage != currentIndex {
        currentIndex = sender.currentPage
        let indexPath = IndexPath(item: currentIndex, section: 0)
        self.carousalCollection?.scrollToItem(at: indexPath, at: .centeredHorizontally, animated: true)
    }
}

Posted the same in SO here
Please help me figure out if something has changed in iOS 14 related to UICollectionView

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant