图片滚动 LTView

来源:互联网 发布:人性实验室 网络暴力 编辑:程序博客网 时间:2024/06/03 16:02
////  AppDelegate.h//  805 作业 图片滚动  LTView////  Created by dllo on 15/8/5.//  Copyright (c) 2015年 flg. All rights reserved.//#import <UIKit/UIKit.h>@interface AppDelegate : UIResponder <UIApplicationDelegate>@property (strong, nonatomic) UIWindow *window;@end
</pre><pre name="code" class="objc"><pre name="code" class="objc">////  AppDelegate.m//  805 作业 图片滚动  LTView////  Created by dllo on 15/8/5.//  Copyright (c) 2015年 flg. All rights reserved.//#import "AppDelegate.h"#import "MainViewController.h"@interface AppDelegate ()@end@implementation AppDelegate-  (void)dealloc{    [_window release];    [super dealloc];}- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];    // Override point for customization after application launch.    self.window.backgroundColor = [UIColor whiteColor];    [self.window makeKeyAndVisible];    [_window release];    MainViewController *mainVC=[[MainViewController alloc] init];    self.window.rootViewController=mainVC;    [mainVC release];    return YES;}- (void)applicationWillResignActive:(UIApplication *)application {    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.}- (void)applicationDidEnterBackground:(UIApplication *)application {    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.}- (void)applicationWillEnterForeground:(UIApplication *)application {    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.}- (void)applicationDidBecomeActive:(UIApplication *)application {    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.}- (void)applicationWillTerminate:(UIApplication *)application {    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.}@end


</pre><pre name="code" class="objc">
<pre name="code" class="objc">////  MainViewController.h//  805 作业 图片滚动  LTView////  Created by dllo on 15/8/5.//  Copyright (c) 2015年 flg. All rights reserved.//#import <UIKit/UIKit.h>@interface MainViewController : UIViewController@end


</pre><pre name="code" class="objc"><pre name="code" class="objc">////  MainViewController.m//  805 作业 图片滚动  LTView////  Created by dllo on 15/8/5.//  Copyright (c) 2015年 flg. All rights reserved.//#import "MainViewController.h"#import "CellView.h"#define WIDTH self.view.frame.size.width#define HEIGHT 200@interface MainViewController ()<UIScrollViewDelegate>@property(nonatomic,retain)UIScrollView *scrollView;@end@implementation MainViewController- (void)dealloc{    [_scrollView release];    [super dealloc];}- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view.    CellView *view0=[[CellView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];    [self.view addSubview:view0];    [view0 release];    view0.label1.text=@"哇.好可怕";    view0.label2.text=@"哇.好可怕";    view0.imageView.image=[UIImage imageNamed:@"dodo_06.jpg"];    CellView *view=[[CellView alloc] initWithFrame:CGRectMake(0, 200, self.view.frame.size.width, 200)];    [self.view addSubview:view];    [view release];    view.label1.text=@"胡巴吃东西";    view.label2.text=@"胡巴吃东西";    view.imageView.image=[UIImage imageNamed:@"09.jpg"];    CellView *view1=[[CellView alloc] initWithFrame:CGRectMake(0, 400, self.view.frame.size.width, 200)];    [self.view addSubview:view1];    [view1 release];    view1.label1.text=@"胡巴突突";    view1.label2.text=@"胡巴突突";    view1.imageView.image=[UIImage imageNamed:@"tutu_08.jpg"];    CellView *view2=[[CellView alloc] initWithFrame:CGRectMake(0, 600, self.view.frame.size.width, 200)];    [self.view addSubview:view2];    [view2 release];    view2.label1.text=@"哇.好可怕";    view2.label2.text=@"哇.好可怕";    view2.imageView.image=[UIImage imageNamed:@"dodo_06.jpg"];    CellView *view3=[[CellView alloc] initWithFrame:CGRectMake(0, 800, self.view.frame.size.width, 200)];    [self.view addSubview:view3];    [view3 release];    view3.label1.text=@"胡巴吃东西";    view3.label2.text=@"胡巴吃东西";    view3.imageView.image=[UIImage imageNamed:@"09.jpg"];    self.scrollView=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 200,WIDTH, 200)];    [self.view addSubview:self.scrollView];    [self.scrollView release];    self.scrollView.contentSize=CGSizeMake(WIDTH, 200*5);    self.scrollView.pagingEnabled=YES;    [self.scrollView addSubview:view0];    [self.scrollView addSubview:view];    [self.scrollView addSubview:view1];    [self.scrollView addSubview:view2];    [self.scrollView addSubview:view3];    self.scrollView.delegate=self;    [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(change) userInfo:nil repeats:YES];}//手动-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{    if (self.scrollView.contentOffset.y==HEIGHT*4) {        self.scrollView.contentOffset=CGPointMake(0, HEIGHT * 1);    }else if(self.scrollView.contentOffset.y==200*0){        self.scrollView.contentOffset=CGPointMake(0, HEIGHT * 3);    }}//自动-(void)change{    [self.scrollView setContentOffset:CGPointMake(0, self.scrollView.contentOffset.y+HEIGHT) animated:YES];    if (self.scrollView.contentOffset.y==HEIGHT*4) {        self.scrollView.contentOffset=CGPointMake(0, HEIGHT*1);    }}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}/*#pragma mark - Navigation// In a storyboard-based application, you will often want to do a little preparation before navigation- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {    // Get the new view controller using [segue destinationViewController].    // Pass the selected object to the new view controller.}*/@end


</pre><pre name="code" class="objc"><pre name="code" class="objc">////  CellView.h//  805 作业 图片滚动  LTView////  Created by dllo on 15/8/5.//  Copyright (c) 2015年 flg. All rights reserved.//#import <UIKit/UIKit.h>@interface CellView : UIView@property(nonatomic,retain)UIImageView *imageView;@property(nonatomic,retain)UILabel *label1;@property(nonatomic,retain)UILabel *label2;@property(nonatomic,retain)UIView *view;@property(nonatomic,retain)UIView *view1;@end


</pre><pre name="code" class="objc"><pre name="code" class="objc">////  CellView.m//  805 作业 图片滚动  LTView////  Created by dllo on 15/8/5.//  Copyright (c) 2015年 flg. All rights reserved.//#import "CellView.h"@implementation CellView-(void)dealloc{    [_imageView release];    [_label1 release];    [_label2 release];    [_view release];    [_view1 release];    [super dealloc];}- (instancetype)initWithFrame:(CGRect)frame{    self=[super initWithFrame:frame];    if (self) {        [self createView];    }    return self;}- (void)createView{    self.imageView=[[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];    [self addSubview:self.imageView];    [_imageView release];    self.label1=[[UILabel alloc] initWithFrame:CGRectMake(200, 50, 100, 30)];    [self addSubview:self.label1];    self.label1.backgroundColor=[UIColor lightGrayColor];    [_label1 release];    //self.label1.text=@"胡巴";    self.label1.font=[UIFont systemFontOfSize:20];    self.label2=[[UILabel alloc] initWithFrame:CGRectMake(200, 100, 100, 30)];    [self addSubview:self.label2];    self.label2.backgroundColor=[UIColor lightGrayColor];    [_label2 release];    //self.label2.text=@"胡巴";    self.label2.font=[UIFont systemFontOfSize:10];    self.view=[[UIView alloc] initWithFrame:CGRectMake(0, 200, self.frame.size.width, 2)];    [self addSubview:self.view];    [_view release];    self.view.backgroundColor=[UIColor orangeColor];    self.view1=[[UIView alloc] initWithFrame:CGRectMake(0, 398, self.frame.size.width, 2)];    [self addSubview:self.view1];    [_view1 release];    self.view1.backgroundColor=[UIColor orangeColor];}@end



0 0
原创粉丝点击