简体   繁体   English

如何在Xamarin.iOS项目中使用iCarousel

[英]How to use iCarousel in Xamarin.iOS project

I'm trying to use an iOS library iCarousel in my Xamarin for iOS project. 我正在尝试在Xamarin for iOS项目中使用iOS库iCarousel I made static library in XCode and added it to Xamarin iOS Binding project. 我在XCode中创建了静态库,并将其添加到Xamarin iOS Binding项目中。 Trying to define exports from lib .a file. 尝试定义lib .a文件的导出。 But I don't have any experience with Objective-C, so I have difficulty with the declaration of exports in iOS Binding Project (that can be used as dll in my target project). 但是我没有使用Objective-C的经验,所以我在iOS绑定项目(可以在我的目标项目中用作dll)中声明导出时遇到困难。 I tried to use monotouch-binding-generator to generate needed declarations, but I have a lot errors after compiling iOS Binding Project. 我尝试使用monotouch-binding-generator生成所需的声明,但是在编译iOS Binding Project之后出现很多错误。 Here's my declarations on C#. 这是我对C#的声明。

[BaseType (typeof (UIView))]
interface iCarousel {
    [Export ("id<iCarouselDelegate>")]
    IBOutlet Id<iCarouselDelegate> { get; set;  }

    [Export ("type")]
    iCarouselType Type { get; set;  }

    [Export ("perspective")]
    float Perspective { get; set;  }

    [Export ("decelerationRate")]
    float DecelerationRate { get; set;  }

    [Export ("scrollSpeed")]
    float ScrollSpeed { get; set;  }

    [Export ("bounceDistance")]
    float BounceDistance { get; set;  }

    [Export ("scrollEnabled")]
    bool ScrollEnabled { get; set;  }

    [Export ("bounces")]
    bool Bounces { get; set;  }

    [Export ("scrollOffset")]
    float ScrollOffset { get; set;  }

    [Export ("offsetMultiplier")]
    float OffsetMultiplier { get;  }

    [Export ("contentOffset")]
    SizeF ContentOffset { get; set;  }

    [Export ("viewpointOffset")]
    SizeF ViewpointOffset { get; set;  }

    [Export ("numberOfItems")]
    int NumberOfItems { get;  }

    [Export ("numberOfPlaceholders")]
    int NumberOfPlaceholders { get;  }

    [Export ("currentItemIndex")]
    int CurrentItemIndex { get; set;  }

    [Export ("currentItemView")]
    UIView CurrentItemView { get;  }

    [Export ("indexesForVisibleItems")]
    NSArray IndexesForVisibleItems { get;  }

    [Export ("numberOfVisibleItems")]
    int NumberOfVisibleItems { get;  }

    [Export ("visibleItemViews")]
    NSArray VisibleItemViews { get;  }

    [Export ("itemWidth")]
    float ItemWidth { get;  }

    [Export ("contentView")]
    UIView ContentView { get;  }

    [Export ("toggle")]
    float Toggle { get;  }

    [Export ("stopAtItemBoundary")]
    bool StopAtItemBoundary { get; set;  }

    [Export ("scrollToItemBoundary")]
    bool ScrollToItemBoundary { get; set;  }

    [Export ("useDisplayLink")]
    bool UseDisplayLink { get; set;  }

    [Export ("vertical")]
    bool Vertical { get; set;  }

    [Export ("ignorePerpendicularSwipes")]
    bool IgnorePerpendicularSwipes { get; set;  }

    [Export ("centerItemWhenSelected")]
    bool CenterItemWhenSelected { get; set;  }

    [Export ("IBOutletid<iCarouselDataSource>dataSource")]
    nonatomic, ah_weak IBOutletid<iCarouselDataSource>dataSource ();

    [Export ("scrollByOffset:duration:")]
    void ScrollByOffsetduration (float offset, double duration);

    [Export ("scrollToOffset:duration:")]
    void ScrollToOffsetduration (float offset, double duration);

    [Export ("scrollByNumberOfItems:duration:")]
    void ScrollByNumberOfItemsduration (int itemCount, double duration);

    [Export ("scrollToItemAtIndex:duration:")]
    void ScrollToItemAtIndexduration (int index, double duration);

    [Export ("scrollToItemAtIndex:animated:")]
    void ScrollToItemAtIndexanimated (int index, bool animated);

    [Export ("removeItemAtIndex:animated:")]
    void RemoveItemAtIndexanimated (int index, bool animated);

    [Export ("insertItemAtIndex:animated:")]
    void InsertItemAtIndexanimated (int index, bool animated);

    [Export ("reloadItemAtIndex:animated:")]
    void ReloadItemAtIndexanimated (int index, bool animated);

    [Export ("itemViewAtIndex:")]
    UIView ItemViewAtIndex (int index);

    [Export ("indexOfItemView:")]
    int IndexOfItemView (UIView view);

    [Export ("indexOfItemViewOrSubview:")]
    int IndexOfItemViewOrSubview (UIView view);

    [Export ("offsetForItemAtIndex:")]
    float OffsetForItemAtIndex (int index);

    [Export ("reloadData")]
    void ReloadData ();

}

[BaseType (typeof ())]
[Model]
interface iCarouselDataSource {
    [Abstract]
    [Export ("numberOfItemsInCarousel:")]
    uint NumberOfItemsInCarousel (iCarousel carousel);

    [Abstract]
    [Export ("carousel:viewForItemAtIndex:reusingView:")]
    UIView CarouselviewForItemAtIndexreusingView (iCarousel carousel, uint index, UIView view);

    [Abstract]
    [Export ("numberOfPlaceholdersInCarousel:")]
    uint NumberOfPlaceholdersInCarousel (iCarousel carousel);

    [Abstract]
    [Export ("carousel:placeholderViewAtIndex:reusingView:")]
    UIView CarouselplaceholderViewAtIndexreusingView (iCarousel carousel, uint index, UIView view);

    [Abstract]
    [Export ("numberOfVisibleItemsInCarousel:")]
    uint NumberOfVisibleItemsInCarousel (iCarousel carousel);

}

[BaseType (typeof ())]
[Model]
interface iCarouselDelegate {
    [Export ("carouselWillBeginScrollingAnimation:")]
    void CarouselWillBeginScrollingAnimation (iCarousel carousel);

    [Export ("carouselDidEndScrollingAnimation:")]
    void CarouselDidEndScrollingAnimation (iCarousel carousel);

    [Export ("carouselDidScroll:")]
    void CarouselDidScroll (iCarousel carousel);

    [Export ("carouselCurrentItemIndexUpdated:")]
    void CarouselCurrentItemIndexUpdated (iCarousel carousel);

    [Export ("carouselWillBeginDragging:")]
    void CarouselWillBeginDragging (iCarousel carousel);

    [Export ("carouselDidEndDragging:willDecelerate:")]
    void CarouselDidEndDraggingwillDecelerate (iCarousel carousel, bool decelerate);

    [Export ("carouselWillBeginDecelerating:")]
    void CarouselWillBeginDecelerating (iCarousel carousel);

    [Export ("carouselDidEndDecelerating:")]
    void CarouselDidEndDecelerating (iCarousel carousel);

    [Export ("carousel:itemTransformForOffset:baseTransform:")]
    CATransform3D CarouselitemTransformForOffsetbaseTransform (iCarousel carousel, float offset, CATransform3D transform);

    [Export ("carousel:valueForOption:withDefault:")]
    float CarouselvalueForOptionwithDefault (iCarousel carousel, iCarouselOption option, float value);

    [Export ("carousel:shouldSelectItemAtIndex:")]
    bool CarouselshouldSelectItemAtIndex (iCarousel carousel, int index);

    [Export ("carousel:didSelectItemAtIndex:")]
    void CarouseldidSelectItemAtIndex (iCarousel carousel, int index);

    [Export ("carouselShouldWrap:__attribute__((deprecated))")]
    bool CarouselShouldWrap__attribute__((deprecated)) (iCarousel carousel, (deprecated ));

    [Export ("carouselItemWidth:__attribute__((deprecated))")]
    float CarouselItemWidth__attribute__((deprecated)) (iCarousel carousel, (deprecated ));

    [Export ("carouselOffsetMultiplier:__attribute__((deprecated))")]
    float CarouselOffsetMultiplier__attribute__((deprecated)) (iCarousel carousel, (deprecated ));

    [Export ("carousel:itemAlphaForOffset:__attribute__((deprecated))")]
    float CarouselitemAlphaForOffset__attribute__((deprecated)) (iCarousel carousel, float offset, (deprecated ));

    [Export ("carousel:valueForTransformOption:withDefault:__attribute__((deprecated))")]
    float CarouselvalueForTransformOptionwithDefault__attribute__((deprecated)) (iCarousel carousel, iCarouselOption option, float value, (deprecated ));

}  

How can I fix errors and use iCarousel in my Xamarin.iOS project? 如何在Xamarin.iOS项目中修复错误并使用iCarousel? It's my first project with Xamarin, sorry if question is stupid. 这是我与Xamarin的第一个项目,很抱歉,问题是否愚蠢。

Thanks. 谢谢。

Those ones looks wrong: 那些看起来不对:

[Export ("id<iCarouselDelegate>")]
IBOutlet Id<iCarouselDelegate> { get; set;  }

[...]

[Export ("IBOutletid<iCarouselDataSource>dataSource")]
nonatomic, ah_weak IBOutletid<iCarouselDataSource>dataSource ();

[...]


[Export ("carouselShouldWrap:__attribute__((deprecated))")]
bool CarouselShouldWrap__attribute__((deprecated)) (iCarousel carousel, (deprecated ));

[Export ("carouselItemWidth:__attribute__((deprecated))")]
float CarouselItemWidth__attribute__((deprecated)) (iCarousel carousel, (deprecated ));

[Export ("carouselOffsetMultiplier:__attribute__((deprecated))")]
float CarouselOffsetMultiplier__attribute__((deprecated)) (iCarousel carousel, (deprecated ));

[Export ("carousel:itemAlphaForOffset:__attribute__((deprecated))")]
float CarouselitemAlphaForOffset__attribute__((deprecated)) (iCarousel carousel, float offset, (deprecated ));

[Export ("carousel:valueForTransformOption:withDefault:__attribute__((deprecated))")]
float CarouselvalueForTransformOptionwithDefault__attribute__((deprecated)) (iCarousel carousel, iCarouselOption option, float value, (deprecated ));

For the deprecated ones, remove them, you won't need them. 对于已弃用的组件,请将其删除,您将不需要它们。 For the 2 other ones, start by commenting them out, then fix them. 对于其他两个,首先将其注释掉,然后修复它们。

There's that as well: 还有:

[BaseType (typeof ())]
[Model]
interface iCarouselDelegate {

the delegate usually are [BaseType (typeof (NSObject)] 委托通常是[BaseType (typeof (NSObject)]

Anyway, having a generator helps you to get started, but never expect it to do all the work for you. 无论如何,拥有一个发电机可以帮助您入门,但是永远不要指望它为您完成所有工作。 Don't do the economy of not reading this and knowing a bit about Obj-C 不要因为不读这篇文章而对Obj-C有所了解而浪费精力

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM