iOS Swift - Detect Items present on screen using UICollectionViewCompositionalLayout - uicollectionview

I'm trying to detect which item is on screen after a scroll action on my collection view, I've set the delegate to myself but the methods such as "scrollViewDidEndDecelerating" are not being fired on the scroll action.
I've used a custom collection view layout, using the new (iOS 13 introduced) UICollectionViewCompositionalLayout.
thainks in advance.

Related

tvOS: overlaySKScene in Scenekit's scene prevents touch events on apple tv

I have an overlaySKScene in my scenekit'scene that contains 2 UIButtons. the button opens a table view controller that gives the option navigate to new place in the scene. it seems having focusable objects as overlay blocks the touch events to the scene. is there a way to over come this issue?
Set the "userInteractionEnabled" property of the SKScene to NO.

Bar Button Item : IBAction not fired in View COntroller

At the bottom of the Detail View Controller of a Split View Controller, I have added a Toolbar in the Storyboard. I have added three Bar Button Items in this Toolbar. Each Bar Button Item is hooked to its IBOutlet in the private interface of the Details View Controller, and also hooked to its IBAction implementation in the same controller, for example:- (IBAction)shouldPresentView:(UIBarButtonItem *)sender
The main view contains:
A Webview.
A small rectancgle view at the bottom of the screen, below the webview, created and added programmatically, and containing various buttons. All the buttons stay operational.
When touching any of the Bar Button Items, the button is temporary highlighted, but none of the IBAction methods is triggered (a NSLog() statement in every method is never executed).
After searching and reading equivalent topics, I went through several solutions:
I added manually the Details View Controller as the delegate of the Toolbar in the View Did Load method of the Details View Controller.
I emptied the cache of the Derived Data of the Product.
I checked that every IBOutlet has an address and is not nil.
I tried to add an action SEL manually in the View Did Load method for every Bar Button Item.
I removed the rectangle bottom view to be sure that it was not interfering with the responder chain.
I added a Bar Button Item in the Navigation Bar to check if the same problem occurs: no, the Bar Button Item fires the IBAction method.
Any help would be appreciated.
Developing with iOS 7 SDK in Xcode 5.0.2
The issue was coming from a Tap Gesture that I added to the main view to collect touches on the web view. So the touch on the Bar Button Items was probably captured somewhere by the main view before reaching the UIButtonBarItem. I changed the target of the Tap Gesture to the web view – more logical – and the issue has been solved.

iOS perform action before handling touch events

I'm trying to recreate the Facebook slideout menu trick (yes I know there's lots of libraries already).
When a user touches a button on the screen, a new view controller is switched in and a rendered bitmap of the previous screen is shown in the foreground of this new view. The uiimageview has a pan gesture recogniser attached to it to allow it to be moved around on the screen.
Currently it's requiring two touches to activate the gesture recogniser, once to bring in the new view controller, and once for the pan gesture to move the uiimageview.
My question is, on touch down can I bring in the new view controller and then pass the touch events to the uiimageview? Or is there any other trick that will help?
I haven't managed to achieve this exactly, but instead I've subclassed UIViewController so the root view controller never changes, just the content that's being displayed.

How to create a button that spawns a movable image? iOS 5

I would like to create a button in my UIView that when touched spawns another button under the finger which immediately starts to follow the finger.
I have seen a tutorial here that deals with button following finger, but i can not figure out how to make this button follow finger WITHOUT user tapping it after creation.
Using iOS 5.1 SDK with XCode 4.3.2
Any help?
You can add target/action pairs to a button for various control events: to make something immediately start following your finger, you probably want UIControlEventTouchDown.
Hook up your first button to call a method on your view controller for that control state. In that action method, create your new button, and shove it in a property on your view controller so that you can refer to it later. Also set a BOOL property on your view controller that's called something like shouldTrackButton.
To make the new button follow your finger, I guess the easiest way is a pan gesture recogniser on the superview. Set that up to call a method on your view controller. In that method, if the gesture recogniser's state is UIGestureRecognizerStateChanged, call translationInView: on the gesture recogniser, passing in the view controller's view (i.e. the superview of the buttons). Now, if and only if shouldTrackButton is YES, take the frame of the original button, translate it by that amount (using CGRectApplyAffineTransform and CGAffineTransformMakeTranslation), and set the new button's frame to the result.
Finally, in the same method, if the gesture recogniser's state is UIGestureRecognizerStateEnded, set shouldTrackButton to NO.

Setting Toolbar Items of UINavigationController

In iPhone OS 3.0, you can set the toolbar items of a UINavigationController using the setToolbarItems:animated: method. However, this requires you pass in an array of UIToolbarItems. While I could programmatically create these toolbar items, I'd rather create them in Interface Builder if possible.
With this in mind, I have created a UIToolbar in "MyGreatViewController.xib" and have populated it with the wanted toolbar items. Then, in "MyGreatViewController.m", I get the items from the toolbar and pass them to setToolbarItems:animated::
- (void)viewDidLoad {
[super viewDidLoad];
[self setToolbarItems: [toolbar items]];
}
...where toolbar is an IBOutlet referring to the UIToolbar.
Is this a good approach? Is there a better way to accomplish this? Should I just create the items programmatically?
I don't know if this is documented anywhere, but I've found that in Interface Builder, if you enable the navigation controller's toolbar, you can drag bar items to your view controller, and they will automagically show up in the navigation controller's toolbar.
For example, here's what we can do (using Xcode 3.2 on Snow Leopard):
File->New Project.... Choose Navigation-based Application and create the project.
Open MainWindow.xib in Interface Builder.
Select the Navigation Controller, and in the Attributes inspector, check the "Shows Toolbar" box. This will cause a Toolbar object to appear.
Drag a Bar Button Item from the Library to the toolbar. It will appear in the toolbar. If you check the hierarchy in the NIB, you'll see that this new item is a child of the RootViewController.
It seems that any Bar Button Items added as children of the navigation item will show up in the navigation bar, and any Bar Button Items added as children of the view controller will show up in the toolbar.
(I stumbled on this by accident. If anyone can find documentation for this behavior, or any additional info, I'd like to hear about it.)
It's a perfectly acceptable way of doing it, but do bear in mind that loading xib files is quite expensive on the iPhone, and it may well be faster to create the toolbar items programatically in your viewDidLoad method.