你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS_3_圖片浏覽

iOS_3_圖片浏覽

編輯:IOS開發綜合

BeyondViewController.h

//
//  BeyondViewController.h
//  03_圖片浏覽
//
//  Created by beyond on 14-7-22.
//  Copyright (c) 2014年 com.beyond. All rights reserved.
//

#import 

@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

效果圖


\












  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved