码迷,mamicode.com
首页 > 移动开发 > 详细

iOS_3_图片浏览

时间:2014-07-22 23:49:37      阅读:345      评论:0      收藏:0      [点我收藏+]

标签:ios

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

效果图


bubuko.com,布布扣

bubuko.com,布布扣











iOS_3_图片浏览

标签:ios

原文地址:http://blog.csdn.net/pre_eminent/article/details/38052051

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!