Jiugongge image browser and jiugongge Browser

Source: Internet
Author: User

Jiugongge image browser and jiugongge Browser
# Import "ViewController. h"
# Import "Appfz. h"
@ Interface ViewController ()
@ Property (nonatomic, copy) NSArray * apps; // File Read
@ Property (nonatomic, assign) BOOL B; // determine whether to zoom in or out
@ Property (nonatomic, assign) CGRect cgr; // record the coordinates and sizes of the buttons when they are pressed.
-(NSArray *) apps ;//
@ End

@ Implementation ViewController
// Read data
-(NSArray *) apps
{
If (_ apps = nil ){
NSString * path = [[NSBundle mainBundle] pathForResource: @ "myhous. plist" ofType: nil];
NSArray * arr = [NSArray arrayWithContentsOfFile: path];
NSMutableArray * arrM = [NSMutableArray array];
For (NSDictionary * dic in arr ){
Appfz * app = [Appfz appWithdic: dic];
[ArrM addObject: app];
}
_ Apps = arrM;
}
Return _ apps;
}
-(Void) viewDidLoad {
[Super viewDidLoad];
// Basic data
Int index = 4;
CGFloat appW = 95;
CGFloat appH = 95;
CGFloat apptopY = 30;
CGFloat appjxX = (self. view. frame. size. width-index * appW)/(index + 1 );
CGFloat appjxY = appjxX;
For (int I = 0; I <self. apps. count; I ++ ){
Int X = I/index;
Int Y = I % index;
Appfz * app1 = self. apps [I];
// Add the button cyclically
UIButton * app = [UIButton alloc] init];
App. frame = CGRectMake (appjxX + (appW + appjxX) * Y, apptopY + (appH + appjxY) * X + appjxY, appW, appH );
[App setBackgroundImage: [UIImage imageNamed: app1.icon] forState: UIControlStateNormal];
[App setBackgroundImage: [UIImage imageNamed: app1.icon] forState: UIControlStateHighlighted];
[Self. view addSubview: app];
[App addTarget: self action: @ selector (isbutton :) forControlEvents: UIControlEventTouchDown];
}
}
// Define the button Method
-(IBAction) isbutton :( UIButton *) app
{
If (self. B = NO ){
// Assign the button size to self. cgr before enlarging
Self. cgr = app. frame;
[Self button: app];
}
Else
{
[Self smallImgClick: app];}
}
// Enlarge the image
-(Void) button :( UIButton *) app
{
[UIView animateWithDuration: 1.0 animations: ^ {
App. frame = CGRectMake (0, 30,414,706 );
}];
[Self. view bringSubviewToFront: app];
// Do not zoom in after amplification
Self. B = YES;
}
// Image Restoration
-(Void) smallImgClick :( UIButton *) app1
{
[UIView animateWithDuration: 1.0 animations: ^ {
App1.frame = self. cgr;
}];
[Self. view bringSubviewToFront: app1];
Self. B = NO;
}
-(Void) didReceiveMemoryWarning {
[Super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@ End

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.