2012-01-06 9 views

答えて

3

私は実際にこのことについてブログ記事を書かれています。チェックアウト:

http://blog.touch4apps.com/home/iphone-monotouch-development/monotouch-infinite-loop-image-scroll-view

が、私はUIScrollViewDelegateから

scrollViewDidEndDeceleratingを手渡し、UIScrollViewのに簡単な微調整を行うことが可能できることが分かりました。

Monotouchチームのメンバーは、これまで(これまでどおり)この素晴らしい仕事をしてくれました。また、デリゲートは既にビルトインイベント(この場合はDecelerationEnded)で利用可能です。

いくつかのビューのUIViewControllerクラスの実装を見てみましょう。簡単にするために、nibファイルからではなくコードからUIを追加しています。ビューにはUIScrollViewアイテムがあり、いくつかのイメージをロードします。最後のイメージは最初のイメージとして配置され、次にすべてのイメージがオーダーに配置され、最初のイメージが最後のイメージとして配置されます。

次に、DecelerationEndedのイベントが実際に位置をスワップするために処理されます(高速 - アニメーションなし)ので、ユーザーはわかりません。タッチを追加するために、ページングが有効にされ、もちろんスクロールが隠されているため、実際にスクロール位置にいるユーザーには表示されません。

公共部分クラスのImageScrollViewController:のUIViewController { #regionコンストラクタ

// The IntPtr and initWithCoder constructors are required for items that need 
    // to be able to be created from a xib rather than from managed code 

    public ImageScrollViewController (IntPtr handle) : base(handle) 
    { 
     Initialize(); 
    } 

    [Export("initWithCoder:")] 
    public ImageScrollViewController (NSCoder coder) : base(coder) 
    { 
     Initialize(); 
    } 

    public ImageScrollViewController() : base("ImageScrollViewController", null) 
    { 
     Initialize(); 
    } 

    void Initialize() 
    { 
    } 

    #endregion 

    UIScrollView scrollView; 

    public override void ViewDidLoad() 
    { 
     base.ViewDidLoad(); 

     scrollView = new UIScrollView (new RectangleF (0, 0, 320, 480)); 
     this.View.AddSubview (scrollView); 

     // add the last image (image4) into the first position 
     this.AddImageWithName ("Images/image4.jpg", 0); 

     // add all of the images to the scroll view 
     for (int i = 1; i < 5; i++) { 
      this.AddImageWithName (string.Format ("Images/image{0}.jpg", i), i); 
     } 

     // add the first image (image1) into the last position 
     this.AddImageWithName ("Images/image1.jpg", 5); 

     scrollView.PagingEnabled = true; 
     scrollView.Bounces = true; 
     scrollView.DelaysContentTouches = true; 
     scrollView.ShowsHorizontalScrollIndicator = false; 

     scrollView.ContentSize = new System.Drawing.SizeF (1920, 480); 
     scrollView.ScrollRectToVisible (new RectangleF (320, 0, 320, 480), true); 
     scrollView.DecelerationEnded += HandleDecelerationEnded; 

    } 

    void HandleDecelerationEnded (object sender, EventArgs e) 
    { 
     if (scrollView.ContentOffset.X == 0) 
     {   
      scrollView.ScrollRectToVisible(new RectangleF(1280, 0, 320, 480), false); 
     }  
     else if (scrollView.ContentOffset.X == 1600) 
     {   
      scrollView.ScrollRectToVisible(new RectangleF(320, 0, 320, 480), false); 
     } 
    } 

    void AddImageWithName (string imageString, int position) 
    { 
     // add image to scroll view 
     UIImage image = UIImage.FromFile (imageString); 
     UIImageView imageView = new UIImageView (image); 

     imageView.Frame = new System.Drawing.RectangleF (position * 320, 0, 320, 480); 

     scrollView.AddSubview (imageView); 
    } 
} 

実際にそれで全部です。そしてギブスリンク:http://github.com/sichy/ImageScrollView

ハッピーコーディング!

+0

あなたのプロンプトのためのthaksが実際に私は他の要件.. – KiShOrE

+0

ここに実際のブログの投稿:http://iosbits.co.uk/new/?p=557 –

1

私は要素がループ上にあったようにそれが見えるようにするPickerViewと似た何かをしました。

私は3つのグループで5つのボタンを繰り返して、より長いスクロールビューを作成しようとしています。グループA、B、Cと呼んでください。次に、ScrollViewがC3に達すると、B3にスクロールさせてアニメーション化します。

ユーザーがスクロールしたときにリストの末尾が表示される場合は、スクロールビューの先頭と末尾にダミーグループを追加する必要があります。

編集:ここにコードが必要です。

ViewController.h

#import <UIKit/UIKit.h> 

@interface ViewController : UIViewController <UIScrollViewDelegate> 
{ 
    UIScrollView *myScrollView; 
} 

@property (nonatomic, retain) IBOutlet UIScrollView *myScrollView; 

@end 

ViewController.m

#import "ViewController.h" 

@implementation ViewController 

@synthesize myScrollView; 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    myScrollView.contentSize = CGSizeMake(320, 2300); 
    myScrollView.delegate = self; 

    UIView *buttonBox = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 2300)]; 

    UIButton *buttonA1 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    buttonA1.frame = CGRectMake(0, 0, 320, 92); 
    [buttonA1 setTitle:@"A" forState:UIControlStateNormal]; 
    UIButton *buttonB1 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    buttonB1.frame = CGRectMake(0, 92, 320, 92); 
    [buttonB1 setTitle:@"B" forState:UIControlStateNormal]; 
    UIButton *buttonC1 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    buttonC1.frame = CGRectMake(0, 184, 320, 92); 
    [buttonC1 setTitle:@"C" forState:UIControlStateNormal]; 
    UIButton *buttonD1 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    buttonD1.frame = CGRectMake(0, 276, 320, 92); 
    [buttonD1 setTitle:@"D" forState:UIControlStateNormal]; 
    UIButton *buttonE1 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    buttonE1.frame = CGRectMake(0, 368, 320, 92); 
    [buttonE1 setTitle:@"E" forState:UIControlStateNormal]; 

    UIButton *buttonA2 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    buttonA2.frame = CGRectMake(0, 460, 320, 92); 
    [buttonA2 setTitle:@"A" forState:UIControlStateNormal]; 
    UIButton *buttonB2 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    buttonB2.frame = CGRectMake(0, 552, 320, 92); 
    [buttonB2 setTitle:@"B" forState:UIControlStateNormal]; 
    UIButton *buttonC2 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    buttonC2.frame = CGRectMake(0, 644, 320, 92); 
    [buttonC2 setTitle:@"C" forState:UIControlStateNormal]; 
    UIButton *buttonD2 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    buttonD2.frame = CGRectMake(0, 736, 320, 92); 
    [buttonD2 setTitle:@"D" forState:UIControlStateNormal]; 
    UIButton *buttonE2 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    buttonE2.frame = CGRectMake(0, 828, 320, 92); 
    [buttonE2 setTitle:@"E" forState:UIControlStateNormal]; 

    UIButton *buttonA3 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    buttonA3.frame = CGRectMake(0, 920, 320, 92); 
    [buttonA3 setTitle:@"A" forState:UIControlStateNormal]; 
    UIButton *buttonB3 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    buttonB3.frame = CGRectMake(0, 1012, 320, 92); 
    [buttonB3 setTitle:@"B" forState:UIControlStateNormal]; 
    UIButton *buttonC3 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    buttonC3.frame = CGRectMake(0, 1104, 320, 92); 
    [buttonC3 setTitle:@"C" forState:UIControlStateNormal]; 
    UIButton *buttonD3 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    buttonD3.frame = CGRectMake(0, 1196, 320, 92); 
    [buttonD3 setTitle:@"D" forState:UIControlStateNormal]; 
    UIButton *buttonE3 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    buttonE3.frame = CGRectMake(0, 1288, 320, 92); 
    [buttonE3 setTitle:@"E" forState:UIControlStateNormal]; 

    UIButton *buttonA4 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    buttonA4.frame = CGRectMake(0, 1380, 320, 92); 
    [buttonA4 setTitle:@"A" forState:UIControlStateNormal]; 
    UIButton *buttonB4 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    buttonB4.frame = CGRectMake(0, 1472, 320, 92); 
    [buttonB4 setTitle:@"B" forState:UIControlStateNormal]; 
    UIButton *buttonC4 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    buttonC4.frame = CGRectMake(0, 1564, 320, 92); 
    [buttonC4 setTitle:@"C" forState:UIControlStateNormal]; 
    UIButton *buttonD4 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    buttonD4.frame = CGRectMake(0, 1656, 320, 92); 
    [buttonD4 setTitle:@"D" forState:UIControlStateNormal]; 
    UIButton *buttonE4 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    buttonE4.frame = CGRectMake(0, 1748, 320, 92); 
    [buttonE3 setTitle:@"E" forState:UIControlStateNormal]; 

    UIButton *buttonA5 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    buttonA5.frame = CGRectMake(0, 1840, 320, 92); 
    [buttonA5 setTitle:@"A" forState:UIControlStateNormal]; 
    UIButton *buttonB5 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    buttonB5.frame = CGRectMake(0, 1932, 320, 92); 
    [buttonB5 setTitle:@"B" forState:UIControlStateNormal]; 
    UIButton *buttonC5 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    buttonC5.frame = CGRectMake(0, 2024, 320, 92); 
    [buttonC5 setTitle:@"C" forState:UIControlStateNormal]; 
    UIButton *buttonD5 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    buttonD5.frame = CGRectMake(0, 2116, 320, 92); 
    [buttonD5 setTitle:@"D" forState:UIControlStateNormal]; 
    UIButton *buttonE5 = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    buttonE5.frame = CGRectMake(0, 2208, 320, 92); 
    [buttonE5 setTitle:@"E" forState:UIControlStateNormal]; 

    [buttonBox addSubview:buttonA1]; 
    [buttonBox addSubview:buttonB1]; 
    [buttonBox addSubview:buttonC1]; 
    [buttonBox addSubview:buttonD1]; 
    [buttonBox addSubview:buttonE1]; 
    [buttonBox addSubview:buttonA2]; 
    [buttonBox addSubview:buttonB2]; 
    [buttonBox addSubview:buttonC2]; 
    [buttonBox addSubview:buttonD2]; 
    [buttonBox addSubview:buttonE2]; 
    [buttonBox addSubview:buttonA3]; 
    [buttonBox addSubview:buttonB3]; 
    [buttonBox addSubview:buttonC3]; 
    [buttonBox addSubview:buttonD3]; 
    [buttonBox addSubview:buttonE3]; 
    [buttonBox addSubview:buttonA4]; 
    [buttonBox addSubview:buttonB4]; 
    [buttonBox addSubview:buttonC4]; 
    [buttonBox addSubview:buttonD4]; 
    [buttonBox addSubview:buttonE4]; 
    [buttonBox addSubview:buttonA5]; 
    [buttonBox addSubview:buttonB5]; 
    [buttonBox addSubview:buttonC5]; 
    [buttonBox addSubview:buttonD5]; 
    [buttonBox addSubview:buttonE5]; 

    [myScrollView addSubview:buttonBox]; 

    myScrollView.contentOffset = CGPointMake(0, 920); 
} 

- (void)scrollViewDidScroll:(UIScrollView *)scrollView 
{ 
    if (scrollView.contentOffset.y < 460) myScrollView.contentOffset = CGPointMake(0, scrollView.contentOffset.y + 460); 
    if (scrollView.contentOffset.y > 1380) myScrollView.contentOffset = CGPointMake(0, scrollView.contentOffset.y - 460); 
} 
+0

申し訳ありません私はあなたにコードを表示できますか? – KiShOrE

関連する問題