nicklockwood / iCarousel

A simple, highly customisable, data-driven 3D carousel for iOS and Mac OS
http://www.charcoaldesign.co.uk/source/cocoa#icarousel
Other
12.01k stars 2.58k forks source link

CustomType Swift Error #548

Open yatanadam opened 10 years ago

yatanadam commented 10 years ago

Hi there. I have used your library in my swift code. I have downloaded and checked all your examples. When i use any type of carousel it works well. But when i prefer Custom type it doesnt work well. Views appear very big and they are not to go in my view.

Can you help me what happens there ? How can i fix it?

nicklockwood commented 10 years ago

What code are you using for your custom transform?

yatanadam commented 10 years ago

this is my code override func viewDidLoad() { super.viewDidLoad() carousel.type = .CoverFlow

    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func numberOfItemsInCarousel(carousel: iCarousel!) -> Int
{
    return 4
}

func carousel(carousel: iCarousel!, viewForItemAtIndex index: Int, var reusingView view: UIView!) -> UIView!
{
    var creditCardView:DrawView

    switch  index {
        case 0:
        creditCardView =  DrawView(frame: self.carousel.bounds, customerName: "Ali ASLAN", cardNumber: "2425 2587 4114 3258", validDate: "07/15", cardType: CreditCards.AgroCard)

        case 1:
        creditCardView =    DrawView(frame: self.carousel.bounds, customerName: "Ali ASLAN", cardNumber: "2425 2587 4114 3258", validDate: "07/15", cardType: CreditCards.Business)

   case 2:
        creditCardView =   DrawView(frame: self.carousel.bounds, customerName: "Ali ASLAN", cardNumber: "2425 2587 4114 3258", validDate: "07/15", cardType: CreditCards.Premium)

        default:
        creditCardView =   DrawView(frame: self.carousel.bounds, customerName: "Ali ASLAN", cardNumber: "2425 2587 4114 3258", validDate: "07/15", cardType: CreditCards.Starcard)

    }

    creditCardView.backgroundColor = UIColor.clearColor()

    return  creditCardView
       }

func carousel(carousel: iCarousel!, valueForOption option: iCarouselOption, withDefault value: CGFloat) -> CGFloat
{
    if (option == .Spacing)
    {
        return value * 1.1
    }
    println(value)
    return value
}

func carousel(carousel: iCarousel!, didSelectItemAtIndex index: Int) {
    println("Selected Credit Card Index : \(index)")

}

func carousel(carousel: iCarousel!, itemTransformForOffset offset: CGFloat, baseTransform transform: CATransform3D) -> CATransform3D {
        //implement 'flip3D' style carousel

       var transforms = CATransform3DRotate(transform, CGFloat(M_PI/8.0), 0.0, 1.0, 0.0)
        println( self.carousel.bounds.width)
        return CATransform3DTranslate(transform, 0.0, 0.0, offset * 400);
}

and

self.carousel.bounds = 0,0,400,200

there is what i want http://i.hizliresim.com/b4mL9j.png

there is what i see.

Thanks.

nicklockwood commented 10 years ago

I think you need to do the following:

set self.carousel.clipsToBounds = true

Change your carousel(_, valueForOption:withDefault:) method to:

func carousel(carousel: iCarousel!, valueForOption option: iCarouselOption, withDefault value: CGFloat) -> CGFloat
{
    if (option == .Spacing)
    {
        return value * 1.1
    }
    else if (option == .FadeMax)
    {
        //set opacity based on distance from camera
        return 0.0
    }
    println(value)
    return value
}

See if that helps

yatanadam commented 10 years ago

Now i am too close to what i want. But views still are not rotated. Is it possible rotate views a bit left ? like the image i have added above ? and one more question how to set swipe sensivity? Its too hard to change views now.

is it possible block swiping more if the view is last one ? How to set visible shadow of view? i cant see anything now ?

Thanks.