iOS_3_图片浏览
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
效果图
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。