Android、iOS 发展历史及特性

2019-12-24  本文已影响0人  Jack_King_

Android、iOS的发展历史


系统结构


运行机制

注:应用之间可通过 URL Scheme 或 Universal Links Url(iOS 9.0 开始支持,需要 APP 做适配) 进行通信


后台机制


数据持久化


组件架构

没有组件的概念


Activity

<activity android:name=".MineActivity">
          <intent-filter>
               <action android:name="android.intent.action.MAIN"></action>
               <category android:name="android.intent.category.LAUNCHER"></category>
          </intent-filter>
</activity>
setContentView(R.layout.main_activity);
TextView tvTitle = (TextView) findViewById(R.id.id_tile);
Intent intent = new Intent(this, SecondActivity.class);
startActivity(intent); 

启动A Acivity:onCreate-A -> onStart-A -> onResume-A
从A 跳转B:onPause-A -> onCreate-B -> onStart-B -> onResume-B -> onStop-A
从B回退到A:onPause-B -> onRestart-A -> onStart-A -> onResume-A -> onStop-B -> onDestroy-B (A启动A过程相同)
home或者锁屏:onPause-A -> onStop-A
home回到APP:onRestart-A -> onStart-A -> onResunme-A
直接kill掉进程:没有任何回调

Fragment

FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction ft = fragmentManager.beginTransaction();
Fragment fragment = new Fragment();
blankFragment2 = new BlankFragment2();
ft.add(R.id.fl_frame, fragment, tag);
ft.commit();
// 最简单的 Page 适配器(不考虑任何复用、设计模式)
class PagerAdapter extends FragmentPagerAdapter {
    public PagerAdapter(FragmentManager fm) {
        super(fm);
    }
    @Override
    public Fragment getItem(int position) {
        if (position == 0) {
            return new Fragment1();
        } else {
            return new Fragment2();
        }
    }
    @Override
    public int getCount() {
        return 2;
    }
}

UIViewController

AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
appDelegate.window.rootViewController = [DKTabBarViewController sharedInstance];
UIView *view = [[UIView alloc] init];

XIB 替换了早期的 NIB,NIB 是个二进制文件而 XIB 是个 XML 格式文件可以很直观的进行 diff 操作

UIViewController *viewController2 = [[UIViewController alloc] init];
// navigation 压栈
[self.navigationController pushViewController:viewController2 animated:YES];
// viewController 弹出
[self presentViewController:viewController2 animated:YES completion:^{
  // 跳转完成回调
}];

UINavigationController

// 入栈
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated;
// 重置栈
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated;
// 出栈 - 栈顶移除
- (UIViewController *)popViewControllerAnimated:(BOOL)animated; 
// 出栈 - 移至指定视图
- (NSArray<UIViewController *> *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated;
// 出栈 - 移至栈底视图
- (NSArray<__kindof UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated; 

UITabarController

UIViewController *viewController = [[UIViewController alloc]init];
...
UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:viewController];
...
navigationController.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"首页" image:[UIImage imageNamed:@"home_normal"] selectedImage:[UIImage imageNamed:@"home_highlight"]];
...
self.viewControllers = @[navigationController,...];
self.tabBar.tintColor = [UIColor orangeColor];
self.tabBar.backgroundColor = [UIColor redColor];
self.tabBar.backgroundImage = [UIImage imageWithName:@"tabar_background_image"];

UI 布局方式

[self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
     make.top.equalTo(self.view).offset(16);
     make.right.equalTo(self.view).offset(-16);
     make.width.height.mas_equalTo(20);
}];
上一篇 下一篇

猜你喜欢

热点阅读