亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

iOS開發(fā)實(shí)現(xiàn)簡(jiǎn)單抽屜效果

 更新時(shí)間:2022年08月08日 10:48:47   作者:中二小葦  
這篇文章主要為大家詳細(xì)介紹了iOS開發(fā)實(shí)現(xiàn)簡(jiǎn)單抽屜效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了iOS實(shí)現(xiàn)簡(jiǎn)單抽屜效果的具體代碼,供大家參考,具體內(nèi)容如下

抽屜效果的原理:其實(shí)就是把兩個(gè)子控制器添加到一個(gè)RootViewController中,將子控制器的view添加到RootViewController的view上,然后改變子控制器view的frame實(shí)現(xiàn)抽屜的效果。

下面直接看看我自己寫的一個(gè)小demo。

RootViewController.h

//兩個(gè)子控制器leftView和midView
@property(nonatomic,weak)UIViewController *leftView;
@property(nonatomic,weak)UIViewController *midView;

RootViewController.m

- (void)viewDidLoad {
? ? [super viewDidLoad];

? ? //將leftView和midView添加到self中作為子控制器。將他們的view添加到self.view中
? ? [self addChildViewController:self.leftView];
? ? [self.view addSubview:self.leftView.view];
? ? [self addChildViewController:self.midView];
? ? [self.view addSubview:self.midView.view];

? ? //設(shè)置一個(gè)按鈕點(diǎn)擊實(shí)現(xiàn)抽屜效果
? ? UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
? ? leftButton.frame = CGRectMake(0, 50, 150, 150);
? ? [leftButton addTarget:self action:@selector(leftButtonPressed) forControlEvents:UIControlEventTouchUpInside];
? ? [leftButton setTitle:@"left" forState:UIControlStateNormal];
? ? [self.midView.view addSubview:leftButton];

}

-(void)leftButtonPressed
{
? ? //判斷抽屜是否是展開狀態(tài)
? ? if (self.midView.view.frame.origin.x == 0) {

? ? ? ? //通過動(dòng)畫實(shí)現(xiàn)view.fram的改變
? ? ? ? [UIView animateWithDuration:0.3 animations:^{
? ? ? ? ? ? /* ?W ?H ?屏幕實(shí)際大小宏
? ? ? ? ? ? ?* #define ScreenWidth [UIScreen mainScreen].bounds.size.width
? ? ? ? ? ? ?* #define ScreenHeight [UIScreen mainScreen].bounds.size.height
? ? ? ? ? ? */
? ? ? ? ? ? self.leftView.view.frame = CGRectMake(0, 0, W, H);
? ? ? ? ? ? self.midView.view.frame = CGRectMake(200, 50, W, H-50*2);

? ? ? ? } completion:^(BOOL finished) {
? ? ? ? }];

? ? }else{

? ? ? ? [UIView animateWithDuration:0.3 animations:^{

? ? ? ? ? ? self.midView.view.frame = CGRectMake(0, 0, W, H);

? ? ? ? } completion:^(BOOL finished) {
? ? ? ? }];
? ? }
}

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

? ? self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
? ? LeftViewController *leftView = [[LeftViewController alloc] init];
? ? MidViewController *midView = [[MidViewController alloc]init];
? ? RootViewController *rootView = [[RootViewController alloc]init];
? ? rootView.leftView = leftView;
? ? rootView.midView = midView;
? ? self.window.rootViewController = rootView;
? ? [self.window makeKeyAndVisible];
? ? return YES;
}

運(yùn)行代碼,效果圖如下:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論