终于效果图:
BeyondViewController.h
// // BeyondViewController.h // 03_图片浏览 // // Created by beyond on 14-7-22. // Copyright (c) 2014年 com.beyond. All rights reserved. // #import <UIKit/UIKit.h> @interface BeyondViewController : UIViewController @property (weak, nonatomic) IBOutlet UILabel *pageNoLabel; @property (weak, nonatomic) IBOutlet UIImageView *pictureView; @property (weak, nonatomic) IBOutlet UILabel *descriptionLabel; @property (weak, nonatomic) IBOutlet UIView *viewSetting; - (IBAction)slideValueChanged:(UISlider *)sender; - (IBAction)setting:(UIButton *)sender; // switch 开关 - (IBAction)switchClick:(UISwitch *)sender; // 图片大小 缩放 - (IBAction)sliderScaleValueChanged:(UISlider *)sender; @end
BeyondViewController.m
// // BeyondViewController.m // 03_图片浏览 // // Created by beyond on 14-7-22. // Copyright (c) 2014年 com.beyond. All rights reserved. // #import "BeyondViewController.h" @interface BeyondViewController () { // 从mainBundle中载入plist,返回数组 NSArray *_descArray; } @end @implementation BeyondViewController - (void)viewDidLoad { [super viewDidLoad]; // 从mainBundle中载入plist,返回数组,仅载入一次就可以 // sg_bundle模板代码,1,获得.app基本的包;2,返回基本的包中某个文件的fullPath全路径 NSBundle *mainBundle = [NSBundle mainBundle]; NSString *fullPath = [mainBundle pathForResource:@"descs.plist" ofType:nil]; // 成员变量记住,由于其它方法slideValueChanged中要用到 _descArray = [NSArray arrayWithContentsOfFile:fullPath]; // _descriptionLabel.text = _descArray[0]; } - (IBAction)slideValueChanged:(UISlider *)sender { NSLog(@"%d",(int)sender.value); // 图片名 从0 ~ 15,相应的slide最小值0 最大值15 int pageNo = (int)sender.value; // 1,控制图片显示 NSString *imageName = [NSString stringWithFormat:@"%d.png",pageNo]; _pictureView.image = [UIImage imageNamed:imageName]; // 2,控制标题显示 _pageNoLabel.text = [NSString stringWithFormat:@"%d/16",(pageNo+1)]; // 3,控制描写叙述显示 plist在模拟器中的全path // /Users/beyond/Library/Developer/Xcode/DerivedData/03_图片浏览-cwowmkgqqqqmfcfxckpaqtzykyus/Build/Products/Debug-iphonesimulator/03_图片浏览.app/descs.plist // /Users/beyond/Library/Application Support/iPhone Simulator/7.1/Applications/02291F09-5446-40E2-82AE-18B6D039D88A/03_图片浏览.app/descs.plist // NSString *descPlistFullPath = [[NSBundle mainBundle] pathForResource:@"descs.plist" ofType:nil]; // _descriptionLabel.text = [_descArray objectAtIndex:pageNo]; _descriptionLabel.text = _descArray[pageNo]; } #pragma mark - 设置:1,夜间模式; 2,图片缩放 - (IBAction)setting:(UIButton *)sender { // UIView的类方法 实现动画效果(開始动画) [UIView beginAnimations:nil context:nil]; // 默认动画持续时间是 0.2 [UIView setAnimationDuration:1]; int winHeight = self.view.bounds.size.height; CGFloat targetY = _viewSetting.frame.origin.y==winHeight?(winHeight-self.viewSetting.frame.size.height):winHeight; // 下面三步为OC标准代码,由于OC中不同意直接修该对象中结构体属性的成员的值,要通过中间的暂时结构体变量 CGRect frame = self.viewSetting.frame; frame.origin.y = targetY; self.viewSetting.frame=frame; // UIView的类方法 实现动画效果(结束动画) [UIView commitAnimations]; } - (IBAction)switchClick:(UISwitch *)sender { if (sender.isOn) { self.view.backgroundColor = [UIColor darkGrayColor]; } else { self.view.backgroundColor = [UIColor whiteColor]; } } - (IBAction)sliderScaleValueChanged:(UISlider *)sender { // UIView的类方法 实现动画效果(開始动画) [UIView beginAnimations:nil context:nil]; // 默认动画持续时间是 0.2 [UIView setAnimationDuration:1]; self.pictureView.transform = CGAffineTransformMakeScale(sender.value, sender.value); // UIView的类方法 实现动画效果(结束动画) [UIView commitAnimations]; } @end
效果图