ahmettkeskin / carouselnotificationexample Goto Github PK
View Code? Open in Web Editor NEWNotification Content Extension example
Notification Content Extension example
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.