Autoscrolling infinite effect in .linear type of iCarousel in swift
Thanks @salman for an answer with the help of Salman's answer I got a solution for an infinite solution without jerking issue when carousel type is linear
Please follow the steps given below.
1. Define timer for handle scrolling
_ = Timer.scheduledTimer(timeInterval: 4, target: self, selector: #selector(self.handleTimer), userInfo: nil, repeats: true)
2. Write the delegate method of the carousel and handle wrap type with the help of wrap we solve jerk issue.
func carousel(_ carousel: iCarousel, valueFor option: iCarouselOption, withDefault value: CGFloat) -> CGFloat {
switch option {
case .wrap:
return 1
default:
return value
}
}
3. Method to handle scrolling
func handleTimer() {
var newIndex = self.carousel.currentItemIndex + 1
if newIndex > self.carousel.numberOfItems {
newIndex = 0
}
carousel.scrollToItem(at: newIndex, duration: 0.5)
}
Repeating iCarousel's scrolling
What solved the problem:
var timer: Timer!
self.timer = Timer.scheduledTimer(timeInterval: 3, target: self, selector: #selector(self.handleTimer), userInfo: nil, repeats: true)
func handleTimer(){
self.carousel.scroll(byNumberOfItems: 1, duration: 0.3)
}
Making infinite loop using iCarousel
Yup, this is easy to do in iCarousel:
- (CGFloat)carousel:(iCarousel *)carousel valueForOption:(iCarouselOption)option withDefault:(CGFloat)value {
switch (option) {
case iCarouselOptionWrap:
return YES;
}
return value;
}
Insert in a tableView set to Autoresize cause a scroll issue
I think you can cache height value for every cell in cellForRowAtIndex method and in HeightForRowAtIndex set the corresponding height for that cell.
You can just do this way :
var cellCached = Dictionary<Int,AnyObject>()
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
table.rowHeight = yourCell.yourLabel.frame.origin.y + yourCell.yourLabel.frame.height + 10
cellCached[indexPath.row] = yourTable.rowHeight
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if(tableView == yourTable)
{
if(cellCached[indexPath.row] != nil)
{
return cellCached[indexPath.row] as! CGFloat
}
else
{
return 200
}
}
else
{
return UITableViewAutomaticDimension
}
}
Related Topics
Use of or Operator on Cloudkit Predicate
My Button Is Centered for iPhone 6 and 6 Plus, But Not for iPhone 5
Error: Argument Type Double/String etc. Does Not Conform to Expected Type "Anyobject"
Swift:Program for Addition of 2 Numbers Using Closure
How to Handle Async Requests in Swift
How to Mimic the Description Output
Swift Uitableviewautomaticdimension Is Not Working
Uitextview Linktextattributes Font Attribute Not Applied to Nsattributedstring
Swiftui Mysterious Spacing Between Large Text and Textfield in VStack
Why Does Classa Adopting Protocolb Not Satisfy the Protocolb Requirement
How Could I Request Text from a Website in Swift
Why Can't I Use 'Type' as the Name of an Enum Embedded in a Struct
Initializer for Conditional Binding Must Have Optional Type, Not '[String:Any]'
Swift Conforming Multiple Protocols Inherits from Same Protocol with Associated Type
Unrecognized Selector Sent to Instance When No Related Entities Found in Core Data