zoukankan      html  css  js  c++  java
  • UI常用控件总结(三)

    音频

       //1.设置背景音乐
        //初始化音乐链接
        NSURL *avUrl = [[NSBundle mainBundle] URLForResource:@"背景音乐" withExtension:@"caf"];
        //初始化音乐播放器类
        AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:avUrl error:nil];
        _player = player;
        //循环次数
        _player.numberOfLoops = 10;
        //音量(0~1)
        _player.volume = 0.3;
        //播放
        [_player play];
    
        //2.设置音效
        //设置系统音效ID
        SystemSoundID ID;
        //根据音效名称,获取音效所在地址
        NSString *audioPath = [[NSBundle mainBundle] pathForResource:@"胜利" ofType:@"aiff"];
        //根据地址把音效文件取出
        NSURL *audioUrl = [NSURL fileURLWithPath:audioPath];
        //将url转换为sound ID
        AudioServicesCreateSystemSoundID((__bridge CFURLRef _Nonnull)(audioUrl), &ID);
        //播放(带振动)
        AudioServicesPlayAlertSound(ID);
        //播放(不振动)
        AudioServicesPlaySystemSound(ID);

    动画

    -(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
     //动画方法一(复杂)
     //开始动画
     [UIView beginAnimations:nil context:nil];
     //设置动画时长
     [UIView setAnimationDuration:5];
     //设置动画延迟时间
     [UIView setAnimationDelay:1];
     //设置动画重复次数
     [UIView setAnimationRepeatCount:5];
     //设置自动返回动画
     [UIView setAnimationRepeatAutoreverses:YES];
     //设置动画状态
     [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
     //必须要设置代理才能调用其结束方法
     [UIView setAnimationDelegate:self];
     [UIView setAnimationDidStopSelector:@selector(stop)];
     //提交动画(不能缺少这一步)
     [UIView commitAnimations];
    
     //动画方法二(简单)
     [UIView animateWithDuration:5 animations:^{
     //动画代码
    
     }];
    
     [UIView animateWithDuration:5 animations:^{
     //动画代码
    
     } completion:^(BOOL finished) {
     //动画完成后执行的代码
     }];
     //设置动态缓冲效果
     [UIView animateWithDuration:5 delay:0 usingSpringWithDamping:0.4 initialSpringVelocity:5 options:UIViewAnimationOptionLayoutSubviews animations:^{
    
     } completion:^(BOOL finished) {
    
     }];
     }

    UITabBarController

       //初始化各个控制器
         MyFirstViewController *mFVC = [MyFirstViewController new];
         MySecondViewController *mSVC = [MySecondViewController new];
         MyThirdViewController *mTVC = [MyThirdViewController new];
         //添加到根控制器上
         self.viewControllers = @[mFVC,mSVC,mTVC];
         //给每个视图控制器添加 tab 选项 tabBarItem  ——系统自带的样式
         UITabBarItem *firstItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:101];
         UITabBarItem *secondItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemRecents tag:102];
         UITabBarItem *thirdItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:103];
         //给每个视图控制器添加 tab 选项 tabBarItem  ——自定义的样式(图片加文字描述)
         //取消系统渲染,始终显示用户所用图片
         UIImage *image = [UIImage imageNamed:@"1"];
         image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
         UITabBarItem *firstItem1 = [[UITabBarItem alloc] initWithTitle:@"" image:image selectedImage:image];
         UITabBarItem *secondItem2 = [[UITabBarItem alloc] initWithTitle:@"" image:[UIImage imageNamed:@""] tag:104];
         //设置按钮上面的数字小气泡
         firstItem.badgeValue = @"99+";
         //给最下面的条形框加背景
         self.tabBar.backgroundImage = [UIImage imageNamed:@""];
         //设置item
         mFVC.tabBarItem = firstItem;
         mSVC.tabBarItem = secondItem;
         mTVC.tabBarItem = thirdItem;
         //利用数组设置item字体颜色
         NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:12],NSForegroundColorAttributeName:[UIColor purpleColor]};
         [firstItem setTitleTextAttributes:dic forState:UIControlStateNormal];
         //隐藏tabBar
         self.tabBar.hidden = YES;
  • 相关阅读:
    upc组队赛1 黑暗意志【stl-map】
    upc组队赛1 闪闪发光 【优先队列】
    upc组队赛1 流连人间的苏苏
    POJ 2387 Til the Cows Come Home 【最短路SPFA】
    POJ 2421 Constructing Roads 【最小生成树Kruscal】
    qrcode-使用
    submlie 配置php运行
    composer 安装laravel
    composer 配置镜像
    Laravel-队列
  • 原文地址:https://www.cnblogs.com/my-garden/p/5570287.html
Copyright © 2011-2022 走看看