首页 > 代码库 > iOS_3_图片浏览
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
效果图
iOS_3_图片浏览
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。