• 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.

    }

  • 相关阅读:
    【WPF】【基础】布局系统
    【设计】【托管扩展性框架】 MEF vs 2010 samples
    【wpf】【控件】内容控件
    【Wpf】【debug】Exception has been thrown by the target of an invocation.
    【设计模式】概述
    期待与悲催中的2012
    金额转为大写人民币
    使用vs2005的GridView控件,菜鸟问题。
    Microsoft Visual Studio 2005中使用水晶报表
    将金额小写转化成汉字大写(javascript)
  • 原文地址:https://www.cnblogs.com/adodo/p/5242767.html
Copyright © 2020-2023  润新知