[英]how to load uiview from nib
滑動時我試圖更改視圖。 我已經通過更改背景顏色進行了測試,從而獲得了可滑動的發現。
從那以后,我添加了一個新的view.nib並將類設置為與當前視圖相同。 在此類.h文件中,我已經完成了此操作
@interface MasterViewController : UIViewController <UIGestureRecognizerDelegate>{
UIView *myView;
UIView *secondView;
}
@property (strong, nonatomic) IBOutlet UIView *myView; // attached to Viewcontroller nib
@property (strong, nonatomic) IBOutlet UIView *secondView; // attached to the secondView
- (void)swipedScreen;
MyView是首先出現的主視圖,secondView是我創建並更改其類以與此視圖相關的筆尖的視圖。
從那里,我已經在.m文件中完成了此操作
- (void) setupSwipeGestureRecognizer {
UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipedScreen)];
swipeGesture.direction = (UISwipeGestureRecognizerDirectionRight|UISwipeGestureRecognizerDirectionLeft);
[myView addGestureRecognizer:swipeGesture];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.title = @"Prototype";
[self setupSwipeGestureRecognizer];
}
- (void)swipedScreen
{
// Not sure what to do here.
[[NSBundle mainBundle] loadNibNamed:@"SecondView" owner:self options:nil];
}
我只是不知道要在swipedScreen方法中做什么才能使secondView出現..我想對該視圖進行動畫處理,使其從右側滑入..但此刻實際上僅次於使視圖出現。 。不確定我在這里做錯了什么,但是顯然這是非常基本的。
任何幫助將不勝感激。
正如我評論:
- (void)swipedScreen
{
[UIView animateWithDuration:3.0f delay:0 options:UIViewAnimationOptionCurveLinear
animations:^{
secondView.frame = CGRectMake(180, secondView.frame.origin.y, secondView.frame.size.width, secondView.frame.size.height);
}
completion:^(BOOL finished){
myView.hidden = YES;
}];
}
實際上,您需要更改動畫的X,Y,Width和height值,完成后,我將主視圖myView
設置為隱藏。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.