I have a UICollectionView with horizontally scrolling sections.
In the cell I have a UIButton.
I need to cancel the touches when the user swipes horizontally but it does not work.
touchesShouldCancel(in:) is only called when swiping vertically over the UIButton, not horizontally.
Is there a way to make it work?
Sample code below
import UIKit
class ConferenceVideoSessionsViewController: UIViewController {
let videosController = ConferenceVideoController()
var collectionView: UICollectionView! = nil
var dataSource: UICollectionViewDiffableDataSource
<ConferenceVideoController.VideoCollection, ConferenceVideoController.Video>! = nil
var currentSnapshot: NSDiffableDataSourceSnapshot
<ConferenceVideoController.VideoCollection, ConferenceVideoController.Video>! = nil
static let titleElementKind = "title-element-kind"
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.title = "Conference Videos"
configureHierarchy()
configureDataSource()
}
}
extension ConferenceVideoSessionsViewController {
func createLayout() -> UICollectionViewLayout {
let sectionProvider = { (sectionIndex: Int,
layoutEnvironment: NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection? in
let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),
heightDimension: .fractionalHeight(1.0))
let item = NSCollectionLayoutItem(layoutSize: itemSize)
// if we have the space, adapt and go 2-up + peeking 3rd item
let groupFractionalWidth = CGFloat(layoutEnvironment.container.effectiveContentSize.width > 500 ?
0.425 : 0.85)
let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(groupFractionalWidth),
heightDimension: .absolute(200))
let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitems: [item])
let section = NSCollectionLayoutSection(group: group)
section.orthogonalScrollingBehavior = .continuous
section.interGroupSpacing = 20
section.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 20, bottom: 0, trailing: 20)
return section
}
let config = UICollectionViewCompositionalLayoutConfiguration()
config.interSectionSpacing = 20
let layout = UICollectionViewCompositionalLayout(
sectionProvider: sectionProvider, configuration: config)
return layout
}
}
extension ConferenceVideoSessionsViewController {
func configureHierarchy() {
collectionView = MyUICollectionView(frame: .zero, collectionViewLayout: createLayout())
collectionView.translatesAutoresizingMaskIntoConstraints = false
collectionView.backgroundColor = .systemBackground
view.addSubview(collectionView)
NSLayoutConstraint.activate([
collectionView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
collectionView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
collectionView.topAnchor.constraint(equalTo: view.topAnchor),
collectionView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
])
collectionView.canCancelContentTouches = true
}
func configureDataSource() {
let cellRegistration = UICollectionView.CellRegistration
<ConferenceVideoCell, ConferenceVideoController.Video> { (cell, indexPath, video) in
// Populate the cell with our item description.
cell.buttonView.setTitle("Push, hold and swipe", for: .normal)
cell.titleLabel.text = video.title
}
dataSource = UICollectionViewDiffableDataSource
<ConferenceVideoController.VideoCollection, ConferenceVideoController.Video>(collectionView: collectionView) {
(collectionView: UICollectionView, indexPath: IndexPath, video: ConferenceVideoController.Video) -> UICollectionViewCell? in
// Return the cell.
return collectionView.dequeueConfiguredReusableCell(using: cellRegistration, for: indexPath, item: video)
}
currentSnapshot = NSDiffableDataSourceSnapshot
<ConferenceVideoController.VideoCollection, ConferenceVideoController.Video>()
videosController.collections.forEach {
let collection = $0
currentSnapshot.appendSections([collection])
currentSnapshot.appendItems(collection.videos)
}
dataSource.apply(currentSnapshot, animatingDifferences: false)
}
}
class MyUICollectionView: UICollectionView {
override func touchesShouldCancel(in view: UIView) -> Bool {
print("AH: touchesShouldCancel view \(view.description)")
if view is MyUIButton {
return true
}
return false
}
}
final class MyUIButton: UIButton {
}
class ConferenceVideoCell: UICollectionViewCell {
static let reuseIdentifier = "video-cell-reuse-identifier"
let buttonView = MyUIButton()
let titleLabel = UILabel()
override init(frame: CGRect) {
super.init(frame: frame)
configure()
}
required init?(coder: NSCoder) {
fatalError()
}
}
extension ConferenceVideoCell {
func configure() {
buttonView.translatesAutoresizingMaskIntoConstraints = false
titleLabel.translatesAutoresizingMaskIntoConstraints = false
contentView.addSubview(buttonView)
contentView.addSubview(titleLabel)
titleLabel.font = UIFont.preferredFont(forTextStyle: .caption1)
titleLabel.adjustsFontForContentSizeCategory = true
buttonView.layer.borderColor = UIColor.black.cgColor
buttonView.layer.borderWidth = 1
buttonView.layer.cornerRadius = 4
buttonView.backgroundColor = UIColor.systemPink
let spacing = CGFloat(10)
NSLayoutConstraint.activate([
buttonView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
buttonView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
buttonView.topAnchor.constraint(equalTo: contentView.topAnchor),
titleLabel.topAnchor.constraint(equalTo: buttonView.bottomAnchor, constant: spacing),
titleLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
titleLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
titleLabel.bottomAnchor.constraint(equalTo: contentView.bottomAnchor)
])
}
}
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
We are getting reports from customers that they are not able to play videos in our app after updating their phones to iOS18.3.1.
(Further checking indicates that it happens on all iOS18 versions. It suddenly started occurring from February 18th, 2025)
When checking logs we see that playback is failing due to CoreMediaErrorDomain error -42709.
This is an undocumented error code and hence we do not know the cause of the playback issue.
Does anyone know what this error code means and how the app should handle it?
Reported as FB16638501.
Topic:
Media Technologies
SubTopic:
Streaming
When an auto renewing subscription is "Developer removed from sale", any auto renewal should fail.
Will this make the subscription enter billing "Grace Period"?
Our expectation is that the rewal would fail without entering a "Grace Period".
We have an app with a UITabBarController.
On visionOS it is automatically shown as an ornament (as expected).
However, we would like to temporarily hide it in some situations.
Is it possible to hide/show the ornament representation of the UITabBarController's tab bar?
While debugging a UIKit based app for visionOS we discovered this "magical" _MRUIPlatterOrnamentBackingWindow window that:
Sets itself as the UIWindowScene.keyWindow
Is not included in UIWindowScene.windows
Has a windowLevel of 0 (normal) but is still in front of any other UIWindow in the scene.
Is there any way to make other UIWindows appear in front?
We have experienced an issue where users that have deleted their account later accidentally (we guess...) re-activate their monthly subscription using the Subscription management screen in iOS.
Is there anyway to control this?
When playing several short HLS clips using AVPlayer connected to a TV using Apple's Lightning-to-HDMI adapter (A1438) we often fail with those unknown errors.
CoreMediaErrorDomain -12034
and
CoreMediaErrorDomain -12158
Anyone has any clue what the errors mean?
Environment:
iPhone8
iOS 15.4
Lightning-to-HDMI adapter (A1438)
We are using an ASWebAuthenticationSession to authenticate using an already logged in session in Safari.
This works fine on real hardware.
In Simulator from iOS13.5, the callback URL is always missing the session ID which indicates that ASWebAuthenticationSession couldn't access the cookies.
We are not using session cookies.
As documented here: https://developer.apple.com/documentation/authenticationservices/authenticating_a_user_through_a_web_service
Does anyone have any suggestion how to debug this and figure out if the problem is on our side or iOS side?
Hi,In the documentation it says you must use a sandbox account when testing In-App purchase using the Sandbox.But I just noticed that (currently on 10.3 release) the StoreKit popup is saying "Sandbox" even when using a normal account but the app is an AdHoc build.Is this expected that a normal account also uses the "Sandbox" when running a AdHoc distribution build?Thanks in advance,Anders
Hi,I have some questions about how AVPlayer handles updates of a cookie's expiration time.We do something like this:1) Send a GET request to server which sets authentication cookie. This cookie has a short expiration time, CookieExpiryTime.2) Start AVPlayer. The authentication cookie is included in the AES key request.3) Every n minutes (where n is CookieExpiryTime/2), send new GET request to authentication server to get updated cookie expiration time. By logging all cookies in NSHTTPCookieStorage.sharedHTTPCookieStorage() we can see that the expiration time of the cookie is updated.The problem:When a key is requested after the expiration time of the first cookie from 1), the cookie is no longer included in the AES key request.But shouldn't the updated cookie (with extended expiration time) be considered?Question 1) Does AVPlayer filter out expired cookies when doing the AES key requests?Question 2) Does AVPlayer check NSHTTPCookieStorage.sharedHTTPCookieStorage() for updated cookies after init?Thanks,Anders