zoukankan      html  css  js  c++  java
  • iOS项目--古典音乐浏览

    #import "ShowViewController.h"

    #import "MusicCollectionViewCell.h"

    #import "ViewController.h"

    #import <MediaPlayer/MediaPlayer.h>

    #import <AVFoundation/AVFoundation.h>

    @interface ShowViewController ()<UIScrollViewDelegate>

    @property (nonatomic,strong)AVAudioPlayer *player;

    @end

    @implementation ShowViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        

        

        NSURL *url = [[NSBundle mainBundle]URLForResource:@"不灭" withExtension:@"mp3"];

        self.player = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:nil];

        [self.player play];

        CGFloat imageWidth = self.scrollView.frame.size.width;

        CGFloat imageHeight = self.scrollView.frame.size.height;

        

        for (int i = 0 ; i<15; i++) {

            UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%d",i+1]];

            UIImageView *imgView = [[UIImageView alloc]initWithImage:image];

            CGFloat imageX = i * imageWidth;

            CGFloat imageY = 0;

            imgView.frame =CGRectMake(imageX, imageY, imageWidth, imageHeight);

            [self.scrollView addSubview:imgView];

        }

        

        self.pageCtr.numberOfPages = 15;

        self.scrollView.contentSize = CGSizeMake(15 * imageWidth, 0);

        self.scrollView.delegate = self;

        [self addTimer];

        // Do any additional setup after loading the view.

    }

    -(void)addTimer{

        NSTimer *timer = [NSTimer timerWithTimeInterval:2.0 target:self selector:@selector(nextPage) userInfo:nil repeats:YES];

        [[NSRunLoop mainRunLoop]addTimer:timer forMode:NSRunLoopCommonModes];

    }

    - (IBAction)stopClick {

        int flag = 0;

        flag+=1;

        

        if (flag %2 != 0) {

            [self.player stop];

        }else if (flag %2 == 0){

            [self.player play];

        }

    }

    -(void)nextPage

    {

        int page = (int)self.pageCtr.currentPage;

        

        if (page == 14) {

            page = 0;

        }else{

        

            page++;

        }

        self.scrollView.contentOffset = CGPointMake(page * self.scrollView.frame.size.width, 0);

        

    }

    -(void)scrollViewDidScroll:(UIScrollView *)scrollView{

        

        int page = (self.scrollView.frame.size.width + self.scrollView.contentOffset.x)/self.scrollView.frame.size.width;

        self.pageCtr.currentPage = page;

    }

    -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{

        [self addTimer];

    }

    - (void)didReceiveMemoryWarning {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

  • 相关阅读:
    51nod 1122 机器人走方格 V4(矩阵乘法)
    51nod 1092 回文字符串
    51nod 1254 最大子段和 V2(递推)
    容斥原理求gcd为k的数对个数
    51nod 1115 最大M子段和 V3
    51nod 1053 最大M子段和 V2(贪心)
    洛谷P1792 [国家集训队]种树
    洛谷P1484 种树(反悔贪心,双向链表+堆)
    51 nod 1052 最大M子段和
    51 nod 1051 最大子矩阵和
  • 原文地址:https://www.cnblogs.com/adodo/p/5242767.html
Copyright © 2011-2022 走看看