###前提・実現したいこと
言語:objective-c
viewCell.xibで1つ、小さめのviewを作成しております。
ViewController.mでfor文を利用してviewCell.xibで作成したviewを10個の画面にしここで作成された画面(10個)1つ1つの座標変更する場合どうしたら良いのか。
目的としてはview上に配置してあるbuttonをタップしたらviewの座標を変更(移動)したい。
言葉足らずですが是非ともご教授お願い致します。
###該当のソースコード
ViewController.h
@interface ViewController : UIViewController { IBOutlet UIScrollView *scrollview; viewCell *screen[10]; } @end
ViewController.m
#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; int y = 0; for(int i=0; i<10; i++) { screen[i] = [[viewCell alloc] init]; [screen[i] setTop:self]; [scrollview addSubview:screen[i].view]; CGRect frame = screen[i].view.frame; screen[i].view.autoresizesSubviews = NO; if (i >= 0) { frame.size.height = 70; } frame.origin.y = y; y += frame.size.height; screen[i].view.frame = frame; screen[i].view.autoresizesSubviews = YES; } }
viewCell.h
#import <UIKit/UIKit.h> @interface viewCell : UIViewController { UIViewController *Top; } -(void)setTop:(UIViewController*)t; @end
viewCell.m
#import "viewCell.h" @interface viewCell () @end @implementation viewCell - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void)setTop:(UIViewController*)t; { Top = t; }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。