iPhoneで垂直スクロールのみを示す例を探しています。
Apple が提供する Scrolling の例では、画像を左から右にスワイプできます。
Instagram App
top to bottom
のように画像をスクロールさせたい。私はそれについて調査し、多くの例を見つけましたが、それらはすべて水平スクロールを示しています。
誰もこれを行う方法を知っていますか?
チュートリアルへのリンクを送っていただければ幸いです。
iPhoneで垂直スクロールのみを示す例を探しています。
Apple が提供する Scrolling の例では、画像を左から右にスワイプできます。
Instagram Apptop to bottom
のように画像をスクロールさせたい。
私はそれについて調査し、多くの例を見つけましたが、それらはすべて水平スクロールを示しています。
誰もこれを行う方法を知っていますか?
チュートリアルへのリンクを送っていただければ幸いです。
こんにちは、Appleコードであなたの問題を解決しました。
関数を変更するだけです
- (void)layoutScrollImages
{
UIImageView *view = nil;
NSArray *subviews = [scrollView1 subviews];
// reposition all image subviews in a horizontal serial fashion
CGFloat curXLoc = 0;
for (view in subviews)
{
if ([view isKindOfClass:[UIImageView class]] && view.tag > 0)
{
CGRect frame = view.frame;
frame.origin = CGPointMake(0,curXLoc);
view.frame = frame;
curXLoc += (kScrollObjHeight);
}
}
// set the content size so it can be scrollable
[scrollView1 setContentSize:CGSizeMake(([scrollView1 bounds].size.width),kNumImages * kScrollObjHeight)];
}
または、サンプルが必要な場合は、私があなたにあげます
次のコードを使用して、画像を上から下に、またはその逆にスクロールできます。
- (void)viewDidLoad
{
//....
UISwipeGestureRecognizer *recognizer;
//for scrolling up
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(SwipeUp)]; // calling method SwipeUp
[recognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];
[[self view] addGestureRecognizer:recognizer];
//for scrolling down
UISwipeGestureRecognizer *recognizer1;
recognizer1 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(SwipeDown)]; //calling method SwipeDown
[recognizer1 setDirection:(UISwipeGestureRecognizerDirectionDown)];
[[self view] addGestureRecognizer:recognizer1];
}
//初期化して合成 IBOutlet UIImageView *bgImage;
-(IBAction)SwipeUp
{
[bgImage setImage:[UIImage imageNamed:@"yourImage1"] ];
bgImage.opaque=YES;
[self.view addSubview:bgImage];
}
-(IBAction)SwipeDown
{
[bgImage setImage:[UIImage imageNamed:@"yourImage2"] ];
bgImage.opaque=YES;
[self.view addSubview:bgImage];
}
あなたの目的のためにあなたのリンクを参照してください:
http://idevzilla.com/2010/09/16/uiscrollview-a-really-simple-tutorial/
次のようなコードがあります。
scroll.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height);
width
水平スクロールの場合、 ofcontentSize
プロパティをスクロール ビューの f よりも高い値に設定する必要がありますrame width
。height
同様に、垂直スクロールの場合、 ofcontentSize
プロパティをスクロール ビューの よりも高い値に設定する必要がありますframe height
。
上記のコードでは、次のように実行できます。
scroll.contentSize = CGSizeMake(self.view.frame.size.width, numberOfViews * self.view.frame.size.height);
たとえば、これを行うにはいくつかの方法があります。
画像用の 2*2 グリッドを作成するコード スニペットは次のとおりです。
//Over here adding the image names into the Array
NSMutableArray *imageArray=[[NSMutableArray alloc]init];
[Arr addObject:[UIImage imageNamed:@"image_1.png"]];
[Arr addObject:[UIImage imageNamed:@"image_2.png"]];
[Arr addObject:[UIImage imageNamed:@"image_3.png"]];
[Arr addObject:[UIImage imageNamed:@"image_4.png"]];
[Arr addObject:[UIImage imageNamed:@"image_5.png"]];
// ScrollView の初期化とフレームの設定:
scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0,320, 460)];
[scrollView setBackgroundColor:[UIColor clearColor]];
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
int row = 0;
int column = 0;
for(int i = 0; i < imageArray.count; i++) {
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
button.backgroundColor=[UIColor clearColor];
button.frame = CGRectMake(column*160+0,row*210+10, 160, 190);
[button setImage:[imageArray objectAtIndex:i] forState:UIControlStateNormal];
[button setBackgroundColor:[UIColor clearColor]];
[button addTarget:self action:@selector(chooseCustomImageTapped:) forControlEvents:UIControlEventTouchUpInside];
button.tag = i;
[view1 addSubview:button];
if (column == 1) {
column = 0;
row++;
} else {
column++;
}
}
[scrollView setContentSize:CGSizeMake(320, (row+1) * 210)];
[self.view addSubview:view1];
//Tapping に使用されるメソッドは次のとおりです。
- (IBAction)chooseCustomImageTapped:(id)sender
{
}
scrollView で垂直スクロールの準備ができたら、それに応じて独自のカスタマイズを行うことができます。これがうまくいくことを願っています。
あなたが達成したいことを正しく理解しているかどうかはわかりませんが、基本的には setContentOffset を使用して scrollView の位置を設定できます。
CGPoint bottomOffset = CGPointMake(0, scrollView.contentSize.height - self.scrollView.bounds.size.height);
[scrollView setContentOffset:bottomOffset animated:YES];