text stringlengths 9 39.2M | dir stringlengths 26 295 | lang stringclasses 185
values | created_date timestamp[us] | updated_date timestamp[us] | repo_name stringlengths 1 97 | repo_full_name stringlengths 7 106 | star int64 1k 183k | len_tokens int64 1 13.8M |
|---|---|---|---|---|---|---|---|---|
```objective-c
//
// UITableViewCell+YFDataSource.m
// BigShow1949
//
// Created by on 16/6/30.
//
#import "UITableViewCell+YFDataSource.h"
@implementation UITableViewCell (YFDataSource)
+ (UINib *)nib
{
return [UINib nibWithNibName:NSStringFromClass([self class]) bundle:nil];
}
- (void)configCellWithEntity:(id)entity
{
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MyDataSource/UITableViewCell+YFDataSource.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 97 |
```objective-c
//
// UITableViewCell+YFDataSource.h
// BigShow1949
//
// Created by on 16/6/30.
//
#import <UIKit/UIKit.h>
@interface UITableViewCell (YFDataSource)
/**
* nib
*
* @return nib
*/
+ (UINib *)nib;
/**
* ,cell
*
* @param entity
*/
- (void)configCellWithEntity:(id)entity;
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MyDataSource/UITableViewCell+YFDataSource.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 97 |
```objective-c
//
// ModelOne.h
// BigShow1949
//
// Created by on 16/6/30.
//
#import <Foundation/Foundation.h>
@interface ModelOne : NSObject
@property (nonatomic, strong) NSString *name;
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MyDataSource/ModelOne.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 54 |
```objective-c
//
// SecondTableViewCell.m
// test
//
// Created by on 16/6/29.
//
#import "SecondTableViewCell.h"
#import "ModelTwo.h"
@implementation SecondTableViewCell
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
NSLog(@"dfasdfasdf");
}
- (void)configCellWithEntity:(id)entity
{
if(entity)
{
ModelTwo *model = entity;
self.textLabel.text = model.name;
}
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MyDataSource/SecondTableViewCell.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 142 |
```objective-c
//
// OneTableViewCell.m
// BigShow1949
//
// Created by on 16/6/30.
//
#import "OneTableViewCell.h"
#import "ModelOne.h"
@implementation OneTableViewCell
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (void)configCellWithEntity:(id)entity
{
if(entity)
{
ModelOne *model = entity;
self.textLabel.text = model.name;
}
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MyDataSource/OneTableViewCell.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 138 |
```objective-c
//
// SecondTableViewCell.h
// test
//
// Created by on 16/6/29.
//
#import <UIKit/UIKit.h>
@interface SecondTableViewCell : UITableViewCell
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MyDataSource/SecondTableViewCell.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 41 |
```objective-c
//
// MyDataSourceViewController.m
// BigShow1949
//
// Created by on 16/6/30.
//
#import "MyDataSourceViewController.h"
#import "MyDataSourceViewController2.h"
#import "DataSource1.h"
#import "OneTableViewCell.h"
#import "ModelOne.h"
@interface MyDataSourceViewController ()
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) DataSource1 *datasource;
@property (nonatomic, strong) NSMutableArray *dataArray;
@end
@implementation MyDataSourceViewController
- (void)viewDidLoad {
[super viewDidLoad];
// datasource
[self configDataSource];
// tableview
[self configTableView];
}
- (void)configDataSource
{
// cell
[self configData];
// cell
// [self.tableView registerNib:[OneTableViewCell nib] forCellReuseIdentifier:NSStringFromClass([TCellOne class])];
[self.tableView registerClass:[OneTableViewCell class] forCellReuseIdentifier:NSStringFromClass([OneTableViewCell class])];
__weak __typeof(self) weakSelf = self;
// cell
YFCellSelectedBlock cellSelectedBlock = ^(id obj){ // cell
__strong __typeof(weakSelf) strongSelf = weakSelf;
MyDataSourceViewController2 *vc2 = [[MyDataSourceViewController2 alloc] init];
[strongSelf.navigationController pushViewController:vc2 animated:YES];
};
// dataSource
_datasource = [[DataSource1 alloc] initWithServerData:_dataArray
andCellIdentifier:NSStringFromClass([OneTableViewCell class])];
_datasource.cellSelectedBlock = cellSelectedBlock;
}
- (void)configData
{
//
_dataArray = [[NSMutableArray alloc] init];
//
ModelOne *one = [[ModelOne alloc] init];
ModelOne *two = [[ModelOne alloc] init];
one.name = @"";
two.name = @"";
[_dataArray addObject:one];
[_dataArray addObject:two];
}
- (void)configTableView
{
// _dataSource_tableview,_dataSource
self.tableView.delegate = _datasource;
self.tableView.dataSource = _datasource;
}
- (UITableView *)tableView {
if (!_tableView) {
UITableView *tableView = [[UITableView alloc] init];
tableView.frame = CGRectMake(0, 0, YFScreen.width, YFScreen.height);
tableView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:tableView];
_tableView = tableView;
_tableView.tableFooterView = [UIView new];
}
return _tableView;
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MyDataSource/MyDataSourceViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 538 |
```objective-c
//
// ModelTwo.m
// BigShow1949
//
// Created by on 16/6/30.
//
#import "ModelTwo.h"
@implementation ModelTwo
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MyDataSource/ModelTwo.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 42 |
```objective-c
//
// MVPLogin2ViewController.m
// BigShow1949
//
// Created by apple on 17/8/11.
//
#import "MVPLogin2ViewController.h"
#import "DemoPresenter.h"
#import "DemoViewModel.h"
@interface MVPLogin2ViewController ()<DemoViewProrocol>
@property (nonatomic, strong) IBOutlet UITextField* userNameField;
@property (nonatomic, strong) IBOutlet UITextField* passwordField;
- (IBAction) submitButtonTapped:(id) sender;
@property (nonatomic, weak) id<DemoPresenterProtocol>presenterDelegate;
@end
@implementation MVPLogin2ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
DemoPresenter *presenter = [[DemoPresenter alloc] init];
presenter.viewDelegate = self;
self.presenterDelegate = presenter;
}
- (IBAction)submitButtonTapped:(id)sender
{
DemoViewModel* viewModel = [[DemoViewModel alloc] init];
viewModel.userName = self.userNameField.text;
viewModel.password = self.passwordField.text;
[self.presenterDelegate doLoginRequest:viewModel];
}
#pragma mark - DemoViewProrocol Methods
- (void) showPasswordInvalidInfo
{
NSLog(@"");
}
- (void) onRequestStart
{
NSLog(@"");
}
- (void) onRequestSuccess
{
NSLog(@"");
}
- (void) onRequestError
{
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Login2/MVPLogin2ViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 295 |
```objective-c
//
// DemoViewModel.h
// BigShow1949
//
// Created by apple on 17/8/11.
//
#import <Foundation/Foundation.h>
@interface DemoViewModel : NSObject
@property (nonatomic, copy) NSString* userName;
@property (nonatomic, copy) NSString* password;
- (bool) isPasswordValid;
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Login2/DemoViewModel.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 72 |
```objective-c
//
// MVPLogin2ViewController.h
// BigShow1949
//
// Created by apple on 17/8/11.
//
#import <UIKit/UIKit.h>
@interface MVPLogin2ViewController : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Login2/MVPLogin2ViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 48 |
```objective-c
//
// MyBaseDataSource.h
// BigShow1949
//
// Created by on 16/6/30.
//
#import <Foundation/Foundation.h>
typedef void(^YFCellSelectedBlock)(id obj);
typedef void (^YFCellBackBlock)(id cell , id data);
@interface MyBaseDataSource : NSObject<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, copy) NSString *cellIdentifier; // cell
@property (nonatomic, copy) NSArray *serverData; // cell
@property (nonatomic, copy) YFCellSelectedBlock cellSelectedBlock; // cell
@property (nonatomic, copy) YFCellBackBlock cellBackBlock; // cellmodel,
/**
* dataSource
*
* @param serverData
* @param identifiers cell
*
* @return Datasource
*/
- (id)initWithServerData:(NSArray *)serverData
andCellIdentifier:(NSString *)identifier;
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MyDataSource/MyBaseDataSource.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 196 |
```objective-c
//
// DemoPresenter.m
// BigShow1949
//
// Created by apple on 17/8/11.
//
#import "DemoPresenter.h"
@implementation DemoPresenter
- (void) doLoginRequest:(DemoViewModel*)viewModel {
if ([viewModel isPasswordValid]) {
//
//
if ([self.viewDelegate respondsToSelector:@selector(onRequestStart)] ) {
[self.viewDelegate onRequestStart];
}
//
sleep(3);
//
if ([self.viewDelegate respondsToSelector:@selector(onRequestSuccess)] ) {
[self.viewDelegate onRequestSuccess];
}
}else {
if ([self.viewDelegate respondsToSelector:@selector(showPasswordInvalidInfo)]) {
[self.viewDelegate showPasswordInvalidInfo];
}
}
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Login2/DemoPresenter.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 166 |
```objective-c
//
// DemoPresenterProtocol.h
// BigShow1949
//
// Created by apple on 17/8/11.
//
#import <Foundation/Foundation.h>
#import "DemoViewModel.h"
@protocol DemoPresenterProtocol <NSObject>
- (void) doLoginRequest:(DemoViewModel*)viewModel;
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Login2/DemoPresenterProtocol.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 65 |
```objective-c
//
// DemoViewProrocol.h
// BigShow1949
//
// Created by apple on 17/8/11.
//
#import <Foundation/Foundation.h>
@protocol DemoViewProrocol <NSObject>
//
- (void) showPasswordInvalidInfo;
//
- (void) onRequestStart;
- (void) onRequestSuccess;
- (void) onRequestError;
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Login2/DemoViewProrocol.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 82 |
```objective-c
//
// DemoViewModel.m
// BigShow1949
//
// Created by apple on 17/8/11.
//
#import "DemoViewModel.h"
#import "PasswordValidator.h"
@implementation DemoViewModel
- (bool) isPasswordValid
{
return [PasswordValidator isValid:_password];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Login2/DemoViewModel.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 67 |
```objective-c
//
// PasswordValidator.h
// BigShow1949
//
// Created by apple on 17/8/11.
//
#import <Foundation/Foundation.h>
@interface PasswordValidator : NSObject
+ (bool) isValid:(NSString*)password;
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Login2/PasswordValidator.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 54 |
```objective-c
//
// PasswordValidator.m
// BigShow1949
//
// Created by apple on 17/8/11.
//
#import "PasswordValidator.h"
@implementation PasswordValidator
+ (bool)isValid:(NSString*)password {
if ([password length] >=6) {
return true;
}
return false;
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Login2/PasswordValidator.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 73 |
```objective-c
//
// DemoPresenter.h
// BigShow1949
//
// Created by apple on 17/8/11.
//
#import <Foundation/Foundation.h>
#import "DemoViewProrocol.h"
#import "DemoPresenterProtocol.h"
@interface DemoPresenter : NSObject<DemoPresenterProtocol>
@property (nonatomic, weak) id<DemoViewProrocol>viewDelegate;
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Login2/DemoPresenter.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 81 |
```objective-c
//
// CounterRepository.m
// BigShow1949
//
// Created by apple on 17/8/11.
//
#import "CounterRepository.h"
@implementation CounterRepository
-(NSInteger)getCurrentValue {
return [[NSUserDefaults standardUserDefaults] integerForKey:@"CounterValueKey"];
}
-(void)setCurrentValue:(NSInteger)value {
[[NSUserDefaults standardUserDefaults] setInteger:value forKey:@"CounterValueKey"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Counter/CounterRepository.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 92 |
```objective-c
//
// CounterRepositoryProtocol.h
// BigShow1949
//
// Created by apple on 17/8/11.
//
#import <Foundation/Foundation.h>
@protocol CounterRepositoryProtocol <NSObject>
-(NSInteger)getCurrentValue;
-(void)setCurrentValue:(NSInteger)value;
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Counter/CounterRepositoryProtocol.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 60 |
```objective-c
//
// CounterPresenter.m
// BigShow1949
//
// Created by apple on 17/8/11.
//
#import "CounterPresenter.h"
@interface CounterPresenter () {
id<CounterRepositoryProtocol> _counterRepository;
id<CounterViewProtocol> _counterView;
}
@end
@implementation CounterPresenter
- (CounterPresenter *)initWithRepository:(id)counterRepository inView:(id)counterView {
if (self = [super init]) {
_counterRepository = counterRepository;
_counterView = counterView;
}
return self;
}
#pragma mark - CounterPresenterProtocol Methods
- (void)getCurrentValue {
NSInteger value = [_counterRepository getCurrentValue];
[_counterView updateCounterValue:[NSString stringWithFormat:@"%ld", (long)value]];
}
- (void)incrementCounter {
NSInteger value = [_counterRepository getCurrentValue];
value = value + 1;
[_counterRepository setCurrentValue:value];
[_counterView updateCounterValue:[NSString stringWithFormat:@"%ld", (long)value]];
}
- (void)decrementCounter {
NSInteger value = [_counterRepository getCurrentValue];
value = value - 1;
[_counterRepository setCurrentValue:value];
[_counterView updateCounterValue:[NSString stringWithFormat:@"%ld", (long)value]];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Counter/CounterPresenter.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 279 |
```objective-c
//
// MVPCounterViewController.h
// BigShow1949
//
// Created by apple on 17/8/11.
//
#import <UIKit/UIKit.h>
/* V
ViewMVCVViewviewcontrollerviewPresenterViewmodel
(counterView, VViewController, view)
*/
@interface MVPCounterViewController : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Counter/MVPCounterViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 72 |
```objective-c
//
// CounterViewProtocol.h
// BigShow1949
//
// Created by apple on 17/8/11.
//
#import <Foundation/Foundation.h>
@protocol CounterViewProtocol <NSObject>
- (void)updateCounterValue:(NSString*)value;
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Counter/CounterViewProtocol.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 58 |
```objective-c
//
// CounterPresenterProtocol.h
// BigShow1949
//
// Created by apple on 17/8/11.
//
#import <Foundation/Foundation.h>
@protocol CounterPresenterProtocol <NSObject>
- (void)getCurrentValue;
- (void)incrementCounter;
- (void)decrementCounter;
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Counter/CounterPresenterProtocol.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 68 |
```objective-c
//
// CounterPresenter.h
// BigShow1949
//
// Created by apple on 17/8/11.
//
#import <Foundation/Foundation.h>
#import "CounterViewProtocol.h"
#import "CounterPresenterProtocol.h"
#import "CounterRepositoryProtocol.h"
/* P
modelviewmodelviewViewmodel
*/
@interface CounterPresenter : NSObject<CounterPresenterProtocol>
- (CounterPresenter *)initWithRepository:(id<CounterRepositoryProtocol>)counterRepository inView:(id<CounterViewProtocol>)counterView;
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Counter/CounterPresenter.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 108 |
```objective-c
//
// MVPCounterViewController.m
// BigShow1949
//
// Created by apple on 17/8/11.
//
#import "MVPCounterViewController.h"
#import "CounterRepository.h"
#import "CounterPresenter.h"
@interface MVPCounterViewController ()<CounterViewProtocol>
{
CounterPresenter *_presenter;
UILabel *_valueLabel;
}
@end
@implementation MVPCounterViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
[self setupUI];
CounterRepository *counterRepository = [[CounterRepository alloc] init];
_presenter = [[CounterPresenter alloc] initWithRepository:counterRepository inView:self];
[_presenter getCurrentValue];
}
- (void)setupUI {
UIButton *incrementBtn = [[UIButton alloc] init];
incrementBtn.frame = CGRectMake(100, 100, 100, 100);
[incrementBtn setTitle:@" " forState:UIControlStateNormal];
[incrementBtn addTarget:self action:@selector(incrementBtnClick) forControlEvents:UIControlEventTouchUpInside];
incrementBtn.backgroundColor = [UIColor redColor];
[self.view addSubview:incrementBtn];
UILabel *countLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 250, 100, 30)];
countLabel.backgroundColor = [UIColor lightGrayColor];
[self.view addSubview:countLabel];
_valueLabel = countLabel;
UIButton *decrementBtn = [[UIButton alloc] init];
decrementBtn.frame = CGRectMake(100, 350, 100, 100);
[decrementBtn setTitle:@" " forState:UIControlStateNormal];
[decrementBtn addTarget:self action:@selector(decrementBtnClick) forControlEvents:UIControlEventTouchUpInside];
decrementBtn.backgroundColor = [UIColor redColor];
[self.view addSubview:decrementBtn];
}
#pragma mark - Actions
- (void)incrementBtnClick {
[_presenter incrementCounter];
}
- (void)decrementBtnClick {
[_presenter decrementCounter];
}
#pragma mark - CounterViewProtocol Methods
- (void)updateCounterValue:(NSString*)value {
_valueLabel.text = value;
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Counter/MVPCounterViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 438 |
```objective-c
//
// YFLittleProjectViewController.h
// BigShow1949
//
// Created by WangMengqi on 15/9/2.
//
#import <UIKit/UIKit.h>
@interface YFLittleProjectViewController : BaseTableViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/06 - LittleProject(小项目展示)/YFLittleProjectViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 55 |
```objective-c
//
// YFLittleProjectViewController.m
// BigShow1949
//
// Created by WangMengqi on 15/9/2.
//
#import "YFLittleProjectViewController.h"
#import "YFRotateButtonViewController.h"
#import "YFLittleProjectVC02.h"
#import "YFLittleProjectVC03.h"
@implementation YFLittleProjectViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setupDataArr:@[@[@"",@"YFRotateButtonViewController"],
@[@"",@"YFLittleProjectVC02"],
@[@"2048",@"YFLittleProjectVC03"],
@[@"",@"YFJigsawViewController"],]];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/06 - LittleProject(小项目展示)/YFLittleProjectViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 147 |
```objective-c
//
// CounterRepository.h
// BigShow1949
//
// Created by apple on 17/8/11.
//
#import <Foundation/Foundation.h>
#import "CounterRepositoryProtocol.h"
/* M
jsonPresenterModel
*/
@interface CounterRepository : NSObject <CounterRepositoryProtocol>
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Counter/CounterRepository.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 64 |
```objective-c
//
// YFRotateButtonViewController.h
// BigShow1949
//
// Created by WangMengqi on 15/9/2.
//
#import <UIKit/UIKit.h>
@interface YFRotateButtonViewController : UIViewController
@property (nonatomic, weak) IBOutlet UIButton *btn;
//
- (IBAction)run:(id)sende;
//
- (IBAction)scale:(id)sender;
//
- (IBAction)rotate:(id)sender;
@end
``` | /content/code_sandbox/BigShow1949/Classes/06 - LittleProject(小项目展示)/01 - RotateButton/YFRotateButtonViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 99 |
```objective-c
//
// YFRotateButtonViewController.m
// BigShow1949
//
// Created by WangMengqi on 15/9/2.
//
// :
#define kDelta 20
#import "YFRotateButtonViewController.h"
@interface YFRotateButtonViewController ()
@end
@implementation YFRotateButtonViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
// UIButton *btn = [[UIButton alloc] init];
//// NSString *str = ;
// btn.transform = cgaf;
// NSLog(@"%@",btn);
}
- (IBAction)run:sende
{
// [UIView beginAnimations:Nil context:nil];
// [UIView setAnimationDuration:0.5];
[UIView animateWithDuration:0.5 animations:^{
CGRect tempFrame = _btn.frame;
int tag = [sende tag];
switch (tag) {
case 1:
tempFrame.origin.y -= kDelta;
break;
case 2:
tempFrame.origin.x += kDelta;
break;
case 3: //
tempFrame.origin.y += kDelta;
break;
case 4: //
tempFrame.origin.x -= kDelta;
break;
default:
break;
}
_btn.frame = tempFrame;
}];
// [UIView commitAnimations];
}
- (IBAction)scale:(id)sender
{
[UIView animateWithDuration:0.5 animations:^{
CGFloat scale = [sender tag] == 20 ? 1.2 : 0.8;
_btn.transform = CGAffineTransformScale(_btn.transform, scale, scale);
}];
// boundscenter
// frame,
}
//
- (IBAction)rotate:(id)sender {
// 45
// _btn.transform = CGAffineTransformMakeRotation(- M_PI_4);
// _btn.transform = CGAffineTransformRotate(_btn.transform, M_PI_4 * (10 == tag?-1:1));
int tag = [sender tag];
if (10 == tag)
_btn.transform = CGAffineTransformRotate(_btn.transform, M_PI_4 * -1);
else
_btn.transform = CGAffineTransformRotate(_btn.transform, M_PI_2);
// M_PI 360M_PI_44
/*
//
CGAffineTransformMakeTranslation(CGFloat tx, <#CGFloat ty#>);
//
CGAffineTransformTranslate(<#CGAffineTransform t#>, <#CGFloat tx#>, <#CGFloat ty#>)
Make
*/
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/06 - LittleProject(小项目展示)/01 - RotateButton/YFRotateButtonViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 552 |
```objective-c
//
// YFLittleProjectVC03.h
// BigShow1949
//
// Created by on 15-9-5.
//
#import <UIKit/UIKit.h>
@interface YFLittleProjectVC03 : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/06 - LittleProject(小项目展示)/03 - 2048/YFLittleProjectVC03.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 52 |
```objective-c
//
// YFRecordData.m
// 2048
//
// Created by apple on 15-6-28.
//
#import "YFRecordData.h"
#import "YFLabel.h"
@implementation YFRecordData
- (YFRecordData *)initWithNowScore:(int)nowScore maxScore:(int)maxScore array:(NSMutableArray *)chesses{
self.nowScore = nowScore;
self.maxScore = maxScore;
self.chesses = [NSMutableArray arrayWithArray:(NSArray *)chesses];
return self;
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/06 - LittleProject(小项目展示)/03 - 2048/YFRecordData.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 121 |
```objective-c
//
// YFLabel.m
// 2048
//
// Created by apple on 15-6-21.
//
#import "YFLabel.h"
@implementation YFLabel
- (instancetype)init{
if (self = [super init]) {
self.canAdd = YES;
}
return self;
}
- (void)moveHereWithRow:(int)row line:(int)line{
self.isLabelMoving = YES;
[UIView animateWithDuration:0.1 animations:^{
self.y = YFPadding_chess + (row - 1) * (YFPadding_chess + YFChessWH);
self.x = YFPadding_chess + (line - 1) * (YFPadding_chess + YFChessWH);
}completion:^(BOOL finished) {
self.isLabelMoving = NO;
}];
self.row = row;
self.line = line;
}
// gettersetter
-(void)setNumber:(int)number{
_number = number;
// label
self.text = [NSString stringWithFormat:@"%d", number];
self.font = [UIFont boldSystemFontOfSize:30];
self.textAlignment = NSTextAlignmentCenter;
// label
// NSLog(@"setter ---nuber -- %zd", number);
switch (number) {
case 2:
self.backgroundColor = YFColor_chess_2;
break;
case 4:
self.backgroundColor = YFColor_chess_4;
break;
case 8:
self.backgroundColor = YFColor_chess_8;
break;
case 16:
self.backgroundColor = YFColor_chess_16;
break;
case 32:
self.backgroundColor = YFColor_chess_32;
break;
case 64:
self.backgroundColor = YFColor_chess_64;
break;
case 128:
self.backgroundColor = YFColor_chess_128;
break;
case 256:
self.backgroundColor = YFColor_chess_256;
break;
case 512:
self.backgroundColor = YFColor_chess_512;
break;
case 1024:
self.backgroundColor = YFColor_chess_1024;
break;
case 2048:
self.backgroundColor = YFColor_chess_2048;
break;
default:
self.backgroundColor = [UIColor blackColor];
break;
}
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/06 - LittleProject(小项目展示)/03 - 2048/YFLabel.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 525 |
```objective-c
//
// YFRecordData.h
// 2048
//
// Created by apple on 15-6-28.
//
#import <Foundation/Foundation.h>
@interface YFRecordData : NSObject
@property (nonatomic, strong) NSMutableArray *chesses; // (:UILabel)
@property (nonatomic, assign) int nowScore;
@property (nonatomic, assign) int maxScore;
- (YFRecordData *)initWithNowScore:(int)nowScore maxScore:(int)maxScore array:(NSMutableArray *)chesses;
@end
``` | /content/code_sandbox/BigShow1949/Classes/06 - LittleProject(小项目展示)/03 - 2048/YFRecordData.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 111 |
```objective-c
//
// YFLabel.h
// 2048
//
// Created by apple on 15-6-21.
//
#import <UIKit/UIKit.h>
#define YFColor_chess_2 YFColor(235, 223, 221)
#define YFColor_chess_4 YFColor(230, 215, 190)
#define YFColor_chess_8 YFColor(240, 160, 105)
#define YFColor_chess_16 YFColor(15, 206, 92)
#define YFColor_chess_32 YFColor(246, 124, 95)
#define YFColor_chess_64 YFColor(237, 207, 114)
#define YFColor_chess_128 YFColor(246, 94, 59)
#define YFColor_chess_256 YFColor(109, 158, 235)
#define YFColor_chess_512 YFColor(241, 194, 50)
#define YFColor_chess_1024 YFColor(255, 0, 255)
#define YFColor_chess_2048 YFColor(255, 0, 0)
//
#define YFPadding_chess 8
// ()
#define YFChessWH (YFScreen.width - 5 * YFPadding_chess) / 4
@interface YFLabel : UILabel
@property (nonatomic, assign) int row;
@property (nonatomic, assign) int line;
@property (nonatomic, assign) int number;
@property (nonatomic, assign) BOOL isLabelMoving;
/**
* ,
*/
@property (nonatomic, assign) BOOL canAdd;
/**
* labelrow line
*/
- (void)moveHereWithRow:(int)row line:(int)line;
@end
``` | /content/code_sandbox/BigShow1949/Classes/06 - LittleProject(小项目展示)/03 - 2048/YFLabel.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 382 |
```objective-c
//
// YFLittleProjectVC02.h
// BigShow1949
//
// Created by on 15-9-5.
//
#import <UIKit/UIKit.h>
@interface YFLittleProjectVC02 : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/06 - LittleProject(小项目展示)/02 - EmotionsKeyboard/YFLittleProjectVC02.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 52 |
```objective-c
//
// YFLittleProjectVC02.m
// BigShow1949
//
// Created by on 15-9-5.
//
#import "YFLittleProjectVC02.h"
#import "SYComposeViewController.h"
@interface YFLittleProjectVC02 ()
@end
@implementation YFLittleProjectVC02
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
UIButton *btn = [[UIButton alloc] init];
btn.backgroundColor = [UIColor lightGrayColor];
[btn setTitle:@"" forState:UIControlStateNormal];
btn.frame = CGRectMake(50, 200, 80, 100);
[btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
- (void)btnClick {
//
UIViewController *rootVc = [UIApplication sharedApplication].keyWindow.rootViewController;
SYComposeViewController *compose = [[SYComposeViewController alloc] init];
[rootVc presentViewController:[[UINavigationController alloc] initWithRootViewController:compose] animated:YES completion:nil];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/06 - LittleProject(小项目展示)/02 - EmotionsKeyboard/YFLittleProjectVC02.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 224 |
```objective-c
//
// YFLittleProjectVC03.m
// BigShow1949
//
// Created by on 15-9-5.
//
#import "YFLittleProjectVC03.h"
#define padding 10
#import "YFLabel.h"
#import "YFRecordData.h"
#define nowScoreBtnPre @" "
#define maxScoreBtnPre @" "
#define revokeBtnPre @" "
@interface YFLittleProjectVC03 ()<UIAlertViewDelegate>
{
// , ,
BOOL _isAllChessesNextHaveNum;
int _nowScore;
int _maxScore;
#warning
//
int _revokeCount;
}
@property (nonatomic, weak) UIView *boardBgView; //
@property (nonatomic, strong) NSMutableArray *chesses; // (:UILabel)
@property (nonatomic, strong) NSMutableArray *tempChesses; //
@property (nonatomic, strong) NSMutableArray *recordDataes; // , YFRecordData
@property (nonatomic, strong) UIButton *nowScoreBtn;
@property (nonatomic, strong) UIButton *maxScoreBtn;
@property (nonatomic, strong) UIButton *revoke;
@end
@implementation YFLittleProjectVC03
- (NSMutableArray *)recordDataes{
if (_recordDataes == nil) {
_recordDataes = [NSMutableArray array];
}
return _recordDataes;
}
- (NSMutableArray *)chesses{
if (_chesses == nil) {
_chesses = [NSMutableArray array];
}
return _chesses;
}
- (void)viewDidLoad{
_maxScore = 20;
_revokeCount = 5;
[self makeContentsView];
[self makeChessWithNumber:2 i:0];
[self makeChessWithNumber:2 i:3];
//
YFRecordData *recordData = [[YFRecordData alloc] initWithNowScore:_nowScore maxScore:_maxScore array:self.chesses];
[self.recordDataes addObject:recordData];
NSLog(@"---");
for (YFRecordData *data in self.recordDataes) {
[self printArray:data.chesses];
NSLog(@"data.chesses:%p, self.chesses:%p", data.chesses, self.chesses);
}
// NSLog(@"");
// for (YFRecordData *data in self.recordDataes) {
// [self printArray:data.chesses];
// }
// BUG
// [self.chesses removeAllObjects]; // self.chesses,self.recordDataes
YFLabel *label = self.chesses[0];
[label moveHereWithRow:3 line:3];
// _nowScore = 30; // ,
// _maxScore = 4;
NSLog(@"chesses");
for (YFRecordData *data in self.recordDataes) {
[self printArray:data.chesses];
}
// 2
// [self randomChess_2];
[self addSwipeGesture];
//
[self.revoke setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
self.revoke.enabled = NO;
// //
// [self makeChessWithNumber:2 i:0];
// [self makeChessWithNumber:4 i:1];
// [self makeChessWithNumber:8 i:2];
// [self makeChessWithNumber:16 i:3];
// [self makeChessWithNumber:32 i:6];
// [self makeChessWithNumber:64 i:7];
// [self makeChessWithNumber:128 i:5];
// [self makeChessWithNumber:256 i:4];
// [self makeChessWithNumber:512 i:9];
// [self makeChessWithNumber:1024 i:10];
// [self makeChessWithNumber:2048 i:12];
}
#pragma mark -
- (void)addSwipeGesture{
UISwipeGestureRecognizer *recognizer;
recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
[self.boardBgView addGestureRecognizer:recognizer];
recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
[self.boardBgView addGestureRecognizer:recognizer];
recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];
[self.boardBgView addGestureRecognizer:recognizer];
recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionDown)];
[self.boardBgView addGestureRecognizer:recognizer];
}
-(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer{
//
self.revoke.enabled = YES;
[self.revoke setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
self.tempChesses = [NSMutableArray arrayWithArray:(NSArray *)self.chesses];
[self swipeDirection:recognizer.direction];
// 0.42
[NSTimer scheduledTimerWithTimeInterval:0.4f target:self selector:@selector(randomChess_2) userInfo:nil repeats:NO];
}
- (void)swipeDirection:(UISwipeGestureRecognizerDirection)direction{
NSLog(@":");
for (YFRecordData *data in self.recordDataes) {
[self printArray:data.chesses];
}
// (), (,)
NSLog(@"_isAllChessesNextHaveNum --- %d", _isAllChessesNextHaveNum);
_isAllChessesNextHaveNum = NO;
while (!_isAllChessesNextHaveNum) { // ,
_isAllChessesNextHaveNum = YES;
for (YFLabel *label in self.chesses) {
switch (direction) {
case UISwipeGestureRecognizerDirectionRight:
[self moveRightWithLabel:label];
break;
case UISwipeGestureRecognizerDirectionLeft:
[self moveLeftWithLabel:label];
break;
case UISwipeGestureRecognizerDirectionUp:
[self moveUpWithLabel:label];
break;
case UISwipeGestureRecognizerDirectionDown:
[self moveDownWithLabel:label];
break;
default:
break;
}
}
}
// , self.chesseslabel, self.chesses
self.chesses = [NSMutableArray arrayWithArray:(NSArray *)self.tempChesses];
// ok,
for (YFLabel *label in self.chesses) {
label.canAdd = YES;
}
}
#pragma mark -
#pragma mark
- (void)moveRightWithLabel:(YFLabel *)label{
if (label.line == 4) return;
BOOL isNextNum = [self isHereHaveNumWithRow:label.row line:(label.line + 1)];
if (isNextNum) { // self.tempChesses
NSLog(@":");
for (YFRecordData *data in self.recordDataes) {
[self printArray:data.chesses];
}
YFLabel *nextLabel = [self getLabelInArrar:self.chesses row:label.row line:label.line + 1];
// YFLabel *nextTempLabel = [self getLabelInArrar:self.tempChesses row:label.row line:label.line + 1];
NSLog(@"");
NSLog(@"label.number --- %d, row:%d, line:%d", label.number, label.row, label.line); // 8
NSLog(@"nextTempLabel.number --- %d, row:%d, line:%d", nextLabel.number, nextLabel.row, nextLabel.line);
NSLog(@"self.chesses:%p, self.tempChesses:%p", self.chesses, self.tempChesses);
// (self.chesses)(self.chesses)
if ((label.number == nextLabel.number) && label.canAdd && nextLabel.canAdd) {
// , ,
nextLabel.number = nextLabel.number * 2;
nextLabel.canAdd = NO;
[self upDateScore:label.number];
// nextTempLabel.number = nextTempLabel.number * 2;
// nextTempLabel.canAdd = NO;
// ()
NSMutableArray *myTempChesses = [NSMutableArray arrayWithArray:self.tempChesses];
for (YFLabel *tempLabel in myTempChesses) {
if (tempLabel.row == label.row && tempLabel.line == label.line) {
[self.tempChesses removeObject:tempLabel];
}
}
NSLog(@",self.tempChesses:");
[self printArray:self.tempChesses];
// tempChesses, self.chesses
// , , ,isHereHaveNumWithRow
[label removeFromSuperview];
label.row = 0;
label.line = 0;
}
}else{ // ,
NSLog(@":");
for (YFRecordData *data in self.recordDataes) {
[self printArray:data.chesses];
}
// ,
_isAllChessesNextHaveNum = NO;
NSLog(@", :%d", label.number);
[label moveHereWithRow:label.row line:label.line + 1];
NSLog(@" :%d :%d", label.row, label.line);
NSLog(@",self.chesses:");
[self printArray:self.chesses];
// self.tempChesses?
// label +1, -1
YFLabel *tempLabel = [self getLabelInArrar:self.tempChesses row:label.row line:label.line - 1];
[tempLabel moveHereWithRow:label.row line:label.line];
NSLog(@",self,tempChesses:");
[self printArray:self.tempChesses];
NSLog(@":");
for (YFRecordData *data in self.recordDataes) {
[self printArray:data.chesses];
}
}
}
- (void)moveLeftWithLabel:(YFLabel *)label{
// line0 label
if (label.line == 1 || label.line == 0) return;
BOOL isNextNum = [self isHereHaveNumWithRow:label.row line:(label.line - 1)];
if (isNextNum) { // self.tempChesses
YFLabel *nextLabel = [self getLabelInArrar:self.chesses row:label.row line:label.line - 1];
YFLabel *nextTempLabel = [self getLabelInArrar:self.tempChesses row:label.row line:label.line - 1];
NSLog(@"");
// (self.chesses)(self.chesses)
if ((label.number == nextLabel.number) && label.canAdd && nextLabel.canAdd) {
// , ,
nextLabel.number = nextLabel.number * 2;
nextLabel.canAdd = NO;
[self upDateScore:label.number];
// nextTempLabel.number = nextTempLabel.number * 2;
// nextTempLabel.canAdd = NO;
// ()
NSMutableArray *myTempChesses = [NSMutableArray arrayWithArray:self.tempChesses];
for (YFLabel *tempLabel in myTempChesses) {
if (tempLabel.row == label.row && tempLabel.line == label.line) {
NSLog(@":%zd, row:%zd, line:%d", tempLabel.number, tempLabel.row, tempLabel.line);
[self.tempChesses removeObject:tempLabel];
}
}
NSLog(@",self.tempChesses:");
[self printArray:self.tempChesses];
// tempChesses, self.chesses
// , , %d,isHereHaveNumWithRow
[label removeFromSuperview];
label.row = 0;
label.line = 0;
}
}else{ // ,
// ,
_isAllChessesNextHaveNum = NO;
NSLog(@", :%d", label.number);
[label moveHereWithRow:label.row line:label.line - 1];
NSLog(@" :%d :%d", label.row, label.line);
NSLog(@",self.chesses:");
[self printArray:self.chesses];
// self.tempChesses?
// label -1, +1
YFLabel *tempLabel = [self getLabelInArrar:self.tempChesses row:label.row line:label.line + 1];
[tempLabel moveHereWithRow:label.row line:label.line];
NSLog(@",self,tempChesses:");
[self printArray:self.tempChesses];
}
}
- (void)moveDownWithLabel:(YFLabel *)label{
if (label.row == 4) return;
BOOL isNextNum = [self isHereHaveNumWithRow:label.row + 1 line:label.line];
if (isNextNum) { // self.tempChesses
YFLabel *nextLabel = [self getLabelInArrar:self.chesses row:label.row + 1 line:label.line];
YFLabel *nextTempLabel = [self getLabelInArrar:self.tempChesses row:label.row + 1 line:label.line];
NSLog(@"");
NSLog(@"label.number --- %zd, row:%zd, line:%d", label.number, label.row, label.line);
NSLog(@"nextTempLabel.number --- %d, row:%d, line:%d", nextLabel.number, nextLabel.row, nextLabel.line);
NSLog(@"self.chesses:%p, self.tempChesses:%p", self.chesses, self.tempChesses);
// (self.chesses)(self.chesses)
if ((label.number == nextLabel.number) && label.canAdd && nextLabel.canAdd) {
// , ,
nextLabel.number = nextLabel.number * 2;
nextLabel.canAdd = NO;
[self upDateScore:label.number];
// nextTempLabel.number = nextTempLabel.number * 2;
// nextTempLabel.canAdd = NO;
// ()
NSMutableArray *myTempChesses = [NSMutableArray arrayWithArray:self.tempChesses];
for (YFLabel *tempLabel in myTempChesses) {
if (tempLabel.row == label.row && tempLabel.line == label.line) {
NSLog(@":%zd, row:%zd, line:%zd", tempLabel.number, tempLabel.row, tempLabel.line);
[self.tempChesses removeObject:tempLabel];
}
}
NSLog(@",self.tempChesses:");
[self printArray:self.tempChesses];
// tempChesses, self.chesses
// , , ,isHereHaveNumWithRow
[label removeFromSuperview];
label.row = 0;
label.line = 0;
}
}else{ // ,
// ,
_isAllChessesNextHaveNum = NO;
NSLog(@", :%d", label.number);
[label moveHereWithRow:label.row + 1 line:label.line];
NSLog(@" :%d :%d", label.row, label.line);
NSLog(@",self.chesses:");
[self printArray:self.chesses];
// self.tempChesses?
// label +1, -1
YFLabel *tempLabel = [self getLabelInArrar:self.tempChesses row:label.row - 1 line:label.line];
[tempLabel moveHereWithRow:label.row line:label.line];
NSLog(@",self,tempChesses:");
[self printArray:self.tempChesses];
}
}
- (void)moveUpWithLabel:(YFLabel *)label{
// line0 label
if (label.row == 1 || label.row == 0) return;
BOOL isNextNum = [self isHereHaveNumWithRow:label.row - 1 line:label.line];
if (isNextNum) { // self.tempChesses
YFLabel *nextLabel = [self getLabelInArrar:self.chesses row:label.row - 1 line:label.line];
YFLabel *nextTempLabel = [self getLabelInArrar:self.tempChesses row:label.row - 1 line:label.line];
NSLog(@"");
NSLog(@"label.number --- %zd, row:%zd, line:%d", label.number, label.row, label.line); // 8
NSLog(@"nextTempLabel.number --- %d, row:%d, line:%d", nextLabel.number, nextLabel.row, nextLabel.line);
NSLog(@"self.chesses:%p, self.tempChesses:%p", self.chesses, self.tempChesses);
// (self.chesses)(self.chesses)
if ((label.number == nextLabel.number) && label.canAdd && nextLabel.canAdd) {
// , ,
nextLabel.number = nextLabel.number * 2;
nextLabel.canAdd = NO;
[self upDateScore:label.number];
// nextTempLabel.number = nextTempLabel.number * 2;
// nextTempLabel.canAdd = NO;
// ()
NSMutableArray *myTempChesses = [NSMutableArray arrayWithArray:self.tempChesses];
for (YFLabel *tempLabel in myTempChesses) {
if (tempLabel.row == label.row && tempLabel.line == label.line) {
NSLog(@":%zd, row:%zd, line:%zd", tempLabel.number, tempLabel.row, tempLabel.line);
[self.tempChesses removeObject:tempLabel];
}
}
NSLog(@",self.tempChesses:");
[self printArray:self.tempChesses];
// tempChesses, self.chesses
// , , ,isHereHaveNumWithRow
[label removeFromSuperview];
label.row = 0;
label.line = 0;
}
}else{ // ,
// ,
_isAllChessesNextHaveNum = NO;
NSLog(@", :%d", label.number);
[label moveHereWithRow:label.row - 1 line:label.line];
NSLog(@" :%d :%d", label.row, label.line);
NSLog(@",self.chesses:");
[self printArray:self.chesses];
// self.tempChesses?
// label -1, +1
YFLabel *tempLabel = [self getLabelInArrar:self.tempChesses row:label.row + 1 line:label.line];
[tempLabel moveHereWithRow:label.row line:label.line];
NSLog(@",self,tempChesses:");
[self printArray:self.tempChesses];
}
}
#pragma mark -
/**
* rowline
*/
- (BOOL)isHereHaveNumWithRow:(int)row line:(int)line{
BOOL isHereNum = false;
for (YFLabel *label in self.chesses) {
if (label.row == row && label.line == line) {
isHereNum = true;
}
}
return isHereNum;
}
/**
* array rowline
*
* : YFLabel
*/
- (YFLabel *)getLabelInArrar:(NSMutableArray *)array row:(int)row line:(int)line{
YFLabel *thisLabel;
for (YFLabel *label in array) {
if (label.row == row && label.line == line) {
thisLabel = label;
}
}
return thisLabel;
}
#pragma mark -
/**
* "2"
*/
- (void)randomChess_2{
NSLog(@"####### 2 ########");
BOOL isHereHaveNum = false;
int i = 0;
//
do {
i = arc4random() % 16 ;
isHereHaveNum = [self isHereHaveNumWithRow:(i/4 + 1) line:(i%4 + 1)];
// NSLog(@"isHereHaveNum --- %d", isHereHaveNum);
} while (isHereHaveNum);
YFLabel *label = [[YFLabel alloc] init];
label.number = 2;
label.row = i/4 + 1;
label.line = i%4 + 1;
label.font = [UIFont boldSystemFontOfSize:30];
label.textAlignment = NSTextAlignmentCenter;
label.backgroundColor = YFColor_chess_2;
CGFloat chessBgViewX = YFPadding_chess + i%4 * (YFPadding_chess + YFChessWH);
CGFloat chessBgViewY = YFPadding_chess + i/4 * (YFPadding_chess + YFChessWH);
label.frame = CGRectMake(chessBgViewX, chessBgViewY, YFChessWH, YFChessWH);
[self.boardBgView addSubview:label];
[self.chesses addObject:label];
if (self.chesses.count == 16) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"!" message:@"" delegate:self cancelButtonTitle:nil otherButtonTitles:@"", nil];
alertView.tag = 1;
[alertView show];
}
NSLog(@":%d", self.chesses.count);
for (YFLabel *label in self.chesses) {
NSLog(@"number:%d, row:%d, line:%d", label.number, label.row, label.line);
}
//
YFRecordData *recordData = [[YFRecordData alloc] init];
recordData.chesses = self.chesses;
recordData.nowScore = _nowScore;
recordData.maxScore = _maxScore;
[self.recordDataes addObject:recordData];
}
#pragma mark - mainView
- (void)makeContentsView{
self.view.backgroundColor = YFColor(237, 237, 237);
CGFloat topBtnH = 44;
CGFloat topBtnW = 100;
UIButton *resetBtn = [[UIButton alloc] init];
[resetBtn setTitle:@"" forState:UIControlStateNormal];
[resetBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
resetBtn.frame = CGRectMake(0, 20, topBtnW, topBtnH);
[self.view addSubview:resetBtn];
UILabel *gameName = [[UILabel alloc] init];
gameName.textAlignment = NSTextAlignmentCenter;
gameName.text = @"2048";
gameName.frame = CGRectMake(0, 0, topBtnW, topBtnH);
gameName.center = CGPointMake(YFScreen.width * 0.5, 20 + topBtnH *0.5);
[self.view addSubview:gameName];
UIButton *setting = [[UIButton alloc] init];
[setting setTitle:@"" forState:UIControlStateNormal];
[setting setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
setting.frame = CGRectMake(YFScreen.width - topBtnW, 20, topBtnW, topBtnH);
[self.view addSubview:setting];
UIView *line = [[UIView alloc] init];
line.backgroundColor = [UIColor blackColor];
line.alpha = 0.1;
line.frame = CGRectMake(0, CGRectGetMaxY(setting.frame) , YFScreen.width, 1);
[self.view addSubview:line];
CGFloat bottomBtnH = 44;
CGFloat bottomBtnW = 90;
CGFloat padding_3 = padding * 3;
//
UIButton *revoke = [[UIButton alloc] init];
self.revoke = revoke;
revoke.backgroundColor = [UIColor blueColor];
revoke.titleLabel.font = [UIFont boldSystemFontOfSize:18];
NSString *revokeTemp = [NSString stringWithFormat:@"%@%d", revokeBtnPre, _revokeCount];
[revoke setTitle:revokeTemp forState:UIControlStateNormal];
[revoke setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
revoke.frame = CGRectMake(padding, CGRectGetMaxY(line.frame) + padding_3, bottomBtnW, bottomBtnH);
[revoke addTarget:self action:@selector(revokeBtnClick) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:revoke];
//
UIButton *nowScoreBtn = [[UIButton alloc] init];
self.nowScoreBtn = nowScoreBtn;
nowScoreBtn.enabled = NO;
nowScoreBtn.backgroundColor = [UIColor lightGrayColor];
NSString *nowScoreBtnTemp = [NSString stringWithFormat:@"%@%@",nowScoreBtnPre, @"0"];
[nowScoreBtn setTitle:nowScoreBtnTemp forState:UIControlStateNormal];
nowScoreBtn.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
nowScoreBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
nowScoreBtn.titleLabel.font = [UIFont systemFontOfSize:15];
[nowScoreBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
nowScoreBtn.frame = CGRectMake(0, 0, bottomBtnW, bottomBtnH);
nowScoreBtn.center = CGPointMake(YFScreen.width * 0.5, revoke.center.y);
[self.view addSubview:nowScoreBtn];
//
UIButton *maxScoreBtn = [[UIButton alloc] init];
self.maxScoreBtn = maxScoreBtn;
maxScoreBtn.enabled = NO;
maxScoreBtn.backgroundColor = YFColor(240, 160, 105);
NSString *maxScoreBtnTemp = [NSString stringWithFormat:@"%@%d", maxScoreBtnPre, _maxScore];
[maxScoreBtn setTitle:maxScoreBtnTemp forState:UIControlStateNormal];
maxScoreBtn.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
maxScoreBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
maxScoreBtn.titleLabel.font = [UIFont systemFontOfSize:14];
[maxScoreBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
maxScoreBtn.frame = CGRectMake(YFScreen.width - padding - bottomBtnW, revoke.frame.origin.y, bottomBtnW, bottomBtnH);
[self.view addSubview:maxScoreBtn];
CGFloat maxY = CGRectGetMaxY(nowScoreBtn.frame) + padding_3;
[self makeCheckerboardWithMaxY:maxY];
}
/**
*
*
* @param boardY
*/
- (void)makeCheckerboardWithMaxY:(CGFloat)boardY{
UIView *boardBgView = [[UIView alloc] init];
self.boardBgView = boardBgView;
boardBgView.backgroundColor = YFColor(173, 158, 145);
boardBgView.frame = CGRectMake(0, boardY, YFScreen.width, YFScreen.width);
[self.view addSubview:boardBgView];
for (int i = 0; i < 4 * 4; i++) {
[self makeChessBgViewWithView:boardBgView i:i];
}
}
/**
*
*
* @param boardBgView
* @param i (4*4)
*/
- (void)makeChessBgViewWithView:(UIView *)boardBgView i:(int)i{
UIView *chessBgView = [[UIView alloc] init];
chessBgView.backgroundColor = YFColor(193, 180, 166);
CGFloat chessBgViewX = YFPadding_chess + i%4 * (YFPadding_chess + YFChessWH);
CGFloat chessBgViewY = YFPadding_chess + i/4 * (YFPadding_chess + YFChessWH);
chessBgView.frame = CGRectMake(chessBgViewX, chessBgViewY, YFChessWH, YFChessWH);
[boardBgView addSubview:chessBgView];
}
#pragma mark - UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (alertView.tag == 1) { //
for (YFLabel *label in self.chesses) {
[label removeFromSuperview];
}
[self.chesses removeAllObjects];
[self randomChess_2];
[self randomChess_2];
}
}
/**
*
*
*
*/
- (void)printArray:(NSMutableArray *)tempChesses{
for (YFLabel *label in tempChesses) {
NSLog(@":%d, row:%d, line:%d", label.number, label.row, label.line);
}
}
/**
*
*
* inumber i:0~15
*/
- (void)makeChessWithNumber:(int)number i:(int)i{
YFLabel *label = [[YFLabel alloc] init];
label.number = number;
label.row = i/4 + 1;
label.line = i%4 + 1;
NSLog(@"row:%d, line:%d", label.row, label.line);
CGFloat chessBgViewX = YFPadding_chess + i%4 * (YFPadding_chess + YFChessWH);
CGFloat chessBgViewY = YFPadding_chess + i/4 * (YFPadding_chess + YFChessWH);
label.frame = CGRectMake(chessBgViewX, chessBgViewY, YFChessWH, YFChessWH);
[self.boardBgView addSubview:label];
[self.chesses addObject:label];
}
/**
*
*/
- (void)revokeBtnClick{
NSLog(@",--self.recordDataes.count:%d", self.recordDataes.count);
for (YFRecordData *data in self.recordDataes) {
NSLog(@"%d:", [self.recordDataes indexOfObject:data]);
[self printArray:data.chesses];
}
if (_revokeCount == 0) {
//
return;
}
if (self.recordDataes.count == 1) {
// ,
return;
}
// ,
[self.chesses removeAllObjects]; //
[self.recordDataes removeLastObject];
YFRecordData *recordData = [self.recordDataes lastObject];
_nowScore = recordData.nowScore;
_maxScore = recordData.maxScore;
self.chesses = recordData.chesses;
//
_revokeCount -= 1;
NSString *revokeTemp = [NSString stringWithFormat:@"%@%d", revokeBtnPre, _revokeCount];
[self.revoke setTitle:revokeTemp forState:UIControlStateNormal];
//
NSString *nowScoreBtnTemp = [NSString stringWithFormat:@"%@%d", nowScoreBtnPre, _nowScore];
[self.nowScoreBtn setTitle:nowScoreBtnTemp forState:UIControlStateNormal];
//
NSString *maxScoreBtnTemp = [NSString stringWithFormat:@"%@%d", maxScoreBtnPre, _maxScore];
[self.maxScoreBtn setTitle:maxScoreBtnTemp forState:UIControlStateNormal];
//
NSLog(@":%d", self.chesses.count);
[self printArray:self.chesses];
}
/**
*
*/
- (void)upDateScore:(int)addScore{
//
_nowScore += addScore;
if (_nowScore >= _maxScore) {
_maxScore = _nowScore;
NSString *maxScoreTemp = [NSString stringWithFormat:@"%@%d", maxScoreBtnPre, _maxScore];
[self.maxScoreBtn setTitle:maxScoreTemp forState:UIControlStateNormal];
}
NSString *norScoreTemp = [NSString stringWithFormat:@"%@%d", nowScoreBtnPre, _nowScore];
[self.nowScoreBtn setTitle:norScoreTemp forState:UIControlStateNormal];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/06 - LittleProject(小项目展示)/03 - 2048/YFLittleProjectVC03.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 6,823 |
```objective-c
//
// SYEmotionButton.m
// 01 -
//
// Created by apple on 15-1-30.
//
#import "SYEmotionButton.h"
#import "SYEmotion.h"
@implementation SYEmotionButton
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
// image, background, background,setHighlighted:
self.adjustsImageWhenHighlighted = NO;
}
return self;
}
- (void)setEmotion:(SYEmotion *)emotion
{
_emotion = emotion;
NSString *name = [NSString stringWithFormat:@"%@/%@", emotion.folder, emotion.png];
[self setImage:[UIImage imageNamed:name] forState:UIControlStateNormal];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/06 - LittleProject(小项目展示)/02 - EmotionsKeyboard/Classes/View/SYEmotionButton.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 152 |
```objective-c
//
// SYEmotionContentView.h
// 01 -
//
// Created by apple on 15-1-30.
//
#import <UIKit/UIKit.h>
@interface SYEmotionContentView : UIView
/**
* (SYEmotion)
*/
@property (nonatomic, strong)NSArray *emotions;
@end
``` | /content/code_sandbox/BigShow1949/Classes/06 - LittleProject(小项目展示)/02 - EmotionsKeyboard/Classes/View/SYEmotionContentView.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 67 |
```objective-c
//
// SYEmotionContentView.m
// 01 -
//
// Created by apple on 15-1-30.
//
//
#define SYClickedEmotion @"SYClickedEmotion"
#define SYEmotionButtonDidClickNotification @"SYEmotionButtonDidClickNotification"
#import "SYEmotionContentView.h"
#import "SYEmotion.h"
#import "SYEmotionButton.h"
static const NSUInteger SYMaxRows = 3;
static const NSUInteger SYMaxCols = 7;
static const NSUInteger SYPageSize = SYMaxCols * SYMaxRows - 1;
@interface SYEmotionContentView() <UIScrollViewDelegate>
@property (nonatomic, weak) UIScrollView *scrollView;
@property (nonatomic, weak) UIView *divider;
@property (nonatomic, weak) UIPageControl *pageControl;
@end
@implementation SYEmotionContentView
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
self.backgroundColor = [UIColor whiteColor];
// 1.UIScollView
UIScrollView *scrollView = [[UIScrollView alloc] init];
scrollView.delegate = self;
scrollView.pagingEnabled = YES;
// ,
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
[self addSubview:scrollView];
self.scrollView = scrollView;
// 2.pageControl
UIPageControl *pageControl = [[UIPageControl alloc] init];
/*
// ,,Pattern,,,
pageControl.pageIndicatorTintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"compose_keyboard_dot_normal"]];
pageControl.currentPageIndicatorTintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"compose_keyboard_dot_selected"]];
// UIPageControl,,KVC
UIImage* _currentPageImage;
UIImage* _pageImage;
:_, pageImage,setter
pageControl.pageImage = [UIImage imageNamed:@"compose_keyboard_dot_normal"];
,,_pageImage
setter,_pageImage
_pageImage
*/
[pageControl setValue:[UIImage imageNamed:@"compose_keyboard_dot_normal"] forKey:@"_pageImage"];
[pageControl setValue:[UIImage imageNamed:@"compose_keyboard_dot_selected"] forKey:@"_currentPageImage"];
[self addSubview:pageControl];
self.pageControl = pageControl;
// 3.
UIView *divider = [[UIView alloc] init];
divider.backgroundColor = [UIColor grayColor];
divider.alpha = 0.5;
[self addSubview:divider];
self.divider = divider;
}
return self;
}
- (void)setEmotions:(NSArray *)emotions
{
_emotions = emotions;
NSUInteger count = emotions.count;
for (NSUInteger i = 0; i < count; i++) {
//
SYEmotionButton *emotionButton = [[SYEmotionButton alloc] init];
emotionButton.emotion = emotions[i];
[emotionButton addTarget:self action:@selector(emotionButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[self.scrollView addSubview:emotionButton];
// //
// SYEmotion *emotion = emotions[i];
// //
// UIButton *button = [[UIButton alloc] init];
// // image, background, background,setHighlighted:
// button.adjustsImageWhenHighlighted = NO;
// //
// NSString *name = [NSString stringWithFormat:@"%@/%@", emotion.folder, emotion.png];
// [button setImage:[UIImage imageNamed:name] forState:UIControlStateNormal];
// [button addTarget:self action:@selector(emotionButtonClick:) forControlEvents:UIControlEventTouchUpInside];
// [self.scrollView addSubview:button];
}
self.pageControl.numberOfPages = (count + SYPageSize - 1) / SYPageSize;
//
for (NSUInteger i = 0; i < self.pageControl.numberOfPages; i++) {
UIButton *button = [[UIButton alloc] init];
[button setImage:[UIImage imageNamed:@"compose_emotion_delete_highlighted"] forState:UIControlStateHighlighted];
[button setImage:[UIImage imageNamed:@"compose_emotion_delete"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(deleteButtonClick) forControlEvents:UIControlEventTouchUpInside];
[self.scrollView addSubview:button];
}
}
/**
*
*/
- (void)emotionButtonClick:(SYEmotionButton *)emotionButton
{
NSDictionary *userInfo = @{SYClickedEmotion : emotionButton.emotion};
[[NSNotificationCenter defaultCenter] postNotificationName:SYEmotionButtonDidClickNotification object:nil userInfo:userInfo];
}
/**
*
*/
- (void)deleteButtonClick
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"SYDeleteButtonDidClickNotification" object:nil];
}
- (void)layoutSubviews
{
[super layoutSubviews];
// 0.pageControl
self.pageControl.width = self.width;
self.pageControl.height = 25;
self.pageControl.y = self.height - self.pageControl.height;
// 1.scrollView
self.scrollView.width = self.width;
self.scrollView.height = self.pageControl.y;
/*
// NSUInteger count = self.scrollView.subviews.count;
NSUInteger count = self.emotions.count;
NSUInteger pageCount = (count + SYPageSize - 1) / SYPageSize;
// if (count % SYPageSize == 0) {
// pageCount = count / SYPageSize;
// }else{
// pageCount = count / SYPageSize + 1;
// }
self.scrollView.contentSize = CGSizeMake(self.scrollView.width * pageCount, 0);
*/
self.scrollView.contentSize = CGSizeMake(self.scrollView.width * self.pageControl.numberOfPages, 0);
// 2.
CGFloat leftMargin = 15;
CGFloat topMargin = 15;
CGFloat buttonW = (self.scrollView.width - 2 * leftMargin) / SYMaxCols;
CGFloat buttonH = (self.scrollView.height - topMargin) / SYMaxRows;
// :count = -
NSUInteger count = self.scrollView.subviews.count - self.pageControl.numberOfPages;
for (NSUInteger i = 0; i < count; i++) {
UIButton *button = self.scrollView.subviews[i];
button.width = buttonW;
button.height = buttonH;
if (i >= SYPageSize) {
UIButton *lastButton = self.scrollView.subviews[i - SYPageSize];
button.y = lastButton.y;
button.x = lastButton.x + self.scrollView.width;
}else{ //
NSUInteger row = i / SYMaxCols;
NSUInteger col = i % SYMaxCols;
button.x = leftMargin + col * buttonW;
button.y = topMargin + row * buttonH;
}
}
// 3.
self.divider.height = 1;
self.divider.width = self.width;
// 4.
for (NSUInteger i = count; i < self.scrollView.subviews.count; i++) {
UIButton *button = self.scrollView.subviews[i];
button.width = buttonW;
button.height = buttonH;
if (i == count) {
button.x = self.scrollView.width - leftMargin -buttonW;
}else{
UIButton *lastButton = self.scrollView.subviews[i - 1];
button.x = lastButton.x + self.scrollView.width;
}
button.y = self.scrollView.height - buttonH;
}
}
#pragma mark - <UIScrollViewDelegate>
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
double pageNo = scrollView.contentOffset.x / scrollView.width;
self.pageControl.currentPage = (int)(pageNo + 0.5);
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/06 - LittleProject(小项目展示)/02 - EmotionsKeyboard/Classes/View/SYEmotionContentView.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 1,557 |
```objective-c
//
// SYTextView.h
// 01 -
//
// Created by apple on 15-1-30.
//
#import <UIKit/UIKit.h>
@interface SYTextView : UITextView
/**
*
*/
@property (nonatomic, copy) NSString *placehoder;
@end
``` | /content/code_sandbox/BigShow1949/Classes/06 - LittleProject(小项目展示)/02 - EmotionsKeyboard/Classes/View/SYTextView.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 59 |
```objective-c
//
// SYEmotionButton.h
// 01 -
//
// Created by apple on 15-1-30.
//
#import <UIKit/UIKit.h>
@class SYEmotion;
@interface SYEmotionButton : UIButton
@property (nonatomic, strong)SYEmotion *emotion;
@end
``` | /content/code_sandbox/BigShow1949/Classes/06 - LittleProject(小项目展示)/02 - EmotionsKeyboard/Classes/View/SYEmotionButton.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 64 |
```objective-c
//
// SYEmotionKeyboard.h
// 01 -
//
// Created by apple on 15-1-30.
//
#import <UIKit/UIKit.h>
@interface SYEmotionKeyboard : UIView
@end
``` | /content/code_sandbox/BigShow1949/Classes/06 - LittleProject(小项目展示)/02 - EmotionsKeyboard/Classes/View/SYEmotionKeyboard.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 47 |
```objective-c
//
// SYEmotionKeyboard.m
// 01 -
//
// Created by apple on 15-1-30.
//
#import "SYEmotionKeyboard.h"
#import "SYEmotionContentView.h"
#import "SYEmotionTool.h"
static NSString * const SYDefaultText = @"";
static NSString * const SYLxhText = @"";
static NSString * const SYRecentText = @"";
// :,,
@interface SYEmotionToolbarButton : UIButton
@end
@implementation SYEmotionToolbarButton
- (void)setHighlighted:(BOOL)highlighted {}
@end
@interface SYEmotionKeyboard()
/** */
@property (nonatomic, weak)UIView *toolbar;
/** */
@property (nonatomic, weak) SYEmotionToolbarButton *selectedButton;
/** */
@property (nonatomic, strong) SYEmotionContentView *recentContentView;
/** */
@property (nonatomic, strong) SYEmotionContentView *defaultContentView;
/** */
@property (nonatomic, strong) SYEmotionContentView *lxhContentView;
/** () */
@property (nonatomic, weak) SYEmotionContentView *selectedContentView;
@end
@implementation SYEmotionKeyboard
- (SYEmotionContentView *)recentContentView
{
if (!_recentContentView) {
self.recentContentView = [[SYEmotionContentView alloc] init];
self.recentContentView.emotions = [SYEmotionTool recentEmotions];
}
return _recentContentView;
}
- (SYEmotionContentView *)defaultContentView
{
if (!_defaultContentView) {
self.defaultContentView = [[SYEmotionContentView alloc] init];
self.defaultContentView.emotions = [SYEmotionTool defaultEmotions];
}
return _defaultContentView;
}
- (SYEmotionContentView *)lxhContentView
{
if (!_lxhContentView) {
self.lxhContentView = [[SYEmotionContentView alloc] init];
self.lxhContentView.emotions = [SYEmotionTool lxhEmotions];
}
return _lxhContentView;
}
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
self.backgroundColor = [UIColor redColor];
// 1.
UIView *toolbar = [[UIView alloc] init];
[self addSubview:toolbar];
self.toolbar = toolbar;
// 2.
[self setupButton:SYRecentText];
[self buttonClick:[self setupButton:SYDefaultText]];
[self setupButton:SYLxhText];
}
return self;
}
/**
*
*
* @param title
*/
- (SYEmotionToolbarButton *)setupButton:(NSString *)title
{
SYEmotionToolbarButton *button = [[SYEmotionToolbarButton alloc] init];
button.titleLabel.font = [UIFont systemFontOfSize:14];
[button setTitle:title forState:UIControlStateNormal];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:@"compose_emotion_table_mid_normal"] forState:UIControlStateNormal];
[button setTitleColor:[UIColor darkGrayColor] forState:UIControlStateDisabled];
[button setBackgroundImage:[UIImage imageNamed:@"compose_emotion_table_mid_selected"] forState:UIControlStateDisabled];
[button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchDown];
[self.toolbar addSubview:button];
return button;
}
- (void)buttonClick:(SYEmotionToolbarButton *)button
{
//
self.selectedButton.enabled = YES;
button.enabled = NO;
self.selectedButton = button;
//
[self.selectedContentView removeFromSuperview];
//
if ([button.currentTitle isEqualToString:SYDefaultText]) {
[self addSubview:self.defaultContentView];
self.selectedContentView = self.defaultContentView;
} else if ([button.currentTitle isEqualToString:SYLxhText]) {
[self addSubview:self.lxhContentView];
self.selectedContentView = self.lxhContentView;
} else if ([button.currentTitle isEqualToString:SYRecentText]) {
[self addSubview:self.recentContentView];
self.selectedContentView = self.recentContentView;
}
}
- (void)layoutSubviews
{
[super layoutSubviews];
// 1.
self.toolbar.x = 0;
self.toolbar.height = 35;
self.toolbar.width = self.width;
self.toolbar.y = self.height - self.toolbar.height;
// 2.
NSUInteger count = self.toolbar.subviews.count;
CGFloat buttonW = self.toolbar.width / count;
for (NSUInteger i = 0; i < count; i++) {
SYEmotionToolbarButton *button = self.toolbar.subviews[i];
button.y = 0;
button.height = self.toolbar.height;
button.width = buttonW;
button.x = i * buttonW;
}
// 3.
self.selectedContentView.width = self.width;
self.selectedContentView.height = self.toolbar.y;
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/06 - LittleProject(小项目展示)/02 - EmotionsKeyboard/Classes/View/SYEmotionKeyboard.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 1,016 |
```objective-c
//
// SYEmotion.h
// 01 -
//
// Created by apple on 15-1-30.
//
#import <Foundation/Foundation.h>
@interface SYEmotion : NSObject
/** png */
@property (nonatomic, copy) NSString *png;
/** */
@property (nonatomic, copy) NSString *chs;
/** */
@property (nonatomic, copy) NSString *folder;
@end
``` | /content/code_sandbox/BigShow1949/Classes/06 - LittleProject(小项目展示)/02 - EmotionsKeyboard/Classes/Model/SYEmotion.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 84 |
```objective-c
//
// SYEmotion.m
// 01 -
//
// Created by apple on 15-1-30.
//
#import "SYEmotion.h"
@implementation SYEmotion
@end
``` | /content/code_sandbox/BigShow1949/Classes/06 - LittleProject(小项目展示)/02 - EmotionsKeyboard/Classes/Model/SYEmotion.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 44 |
```objective-c
//
// ViewController.h
// 01 -
//
// Created by apple on 15-1-30.
//
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/06 - LittleProject(小项目展示)/02 - EmotionsKeyboard/Classes/Controller/ViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 41 |
```objective-c
//
// SYTextView.m
// 01 -
//
// Created by apple on 15-1-30.
//
#import "SYTextView.h"
@implementation SYTextView
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
[self setup];
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
if (self = [super initWithCoder:aDecoder]) {
[self setup];
}
return self;
}
- (void)setup
{
// ,[self setNeedsDisplay],,drawRect:(CGRect)rect
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setNeedsDisplay) name:UITextViewTextDidChangeNotification object:self];
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
// , ,
- (void)setPlacehoder:(NSString *)placehoder
{
_placehoder = [placehoder copy];
[self setNeedsDisplay];
}
// ,
- (void)setFont:(UIFont *)font
{
[super setFont:font];
[self setNeedsDisplay];
}
- (void)setText:(NSString *)text
{
[super setText:text];
[self setNeedsDisplay];
}
- (void)setAttributedText:(NSAttributedString *)attributedText
{
[super setAttributedText:attributedText];
[self setNeedsDisplay];
}
- (void)drawRect:(CGRect)rect
{
if (self.hasText) return;
//
NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
dic[NSForegroundColorAttributeName] = [UIColor grayColor];
//
CGRect placehoderRect;
placehoderRect.origin = CGPointMake(5, 7);
CGFloat w = rect.size.width - 2 * placehoderRect.origin.x;
CGFloat h = rect.size.height;
placehoderRect.size = CGSizeMake(w, h);
[self.placehoder drawInRect:placehoderRect withAttributes:dic];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/06 - LittleProject(小项目展示)/02 - EmotionsKeyboard/Classes/View/SYTextView.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 440 |
```objective-c
//
// ViewController.m
// 01 -
//
// Created by apple on 15-1-30.
//
#import "ViewController.h"
@interface ViewController ()
- (IBAction)emotionKeyboard;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)emotionKeyboard {
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/06 - LittleProject(小项目展示)/02 - EmotionsKeyboard/Classes/Controller/ViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 109 |
```objective-c
//
// SYComposeViewController.h
// 01 -
//
// Created by apple on 15-1-30.
//
#import <UIKit/UIKit.h>
@interface SYComposeViewController : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/06 - LittleProject(小项目展示)/02 - EmotionsKeyboard/Classes/Controller/SYComposeViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 45 |
```objective-c
//
// SYEmotionTool.m
// 01 -
//
// Created by apple on 15-1-30.
//
#import "SYEmotionTool.h"
#import "SYEmotion.h"
#import "MJExtension.h"
@implementation SYEmotionTool
static NSArray *_defaultEmotions;
static NSArray *_recentEmotions;
static NSArray *_lxhEmotions;
/**
*
*/
+ (NSArray *)defaultEmotions
{
if (!_defaultEmotions) {
// 1:
/*
NSString *file = [[NSBundle mainBundle] pathForResource:@"default/info.plist" ofType:nil];
NSArray *dictArray = [NSArray arrayWithContentsOfFile:file];
_defaultEmotions = [SYEmotion objectArrayWithKeyValuesArray:dictArray];
*/
// 2:
/*
NSString *file = [[NSBundle mainBundle] pathForResource:@"default/info.plist" ofType:nil];
_defaultEmotions = [SYEmotion objectArrayWithFile:file];
*/
// :mainBundle
_defaultEmotions = [SYEmotion objectArrayWithFilename:@"default/info.plist"];
// _defaultEmotions, setFolder:,"default"
// emotion.folder = @"default";
// SYLog(@"%@----", _defaultEmotions);
[_defaultEmotions makeObjectsPerformSelector:@selector(setFolder:) withObject:@"default"];
}
return _defaultEmotions;
}
/**
*
*/
+ (NSArray *)recentEmotions
{
return nil;
}
/**
*
*/
+ (NSArray *)lxhEmotions
{
if (!_lxhEmotions) {
_lxhEmotions = [SYEmotion objectArrayWithFilename:@"lxh/info.plist"];
[_lxhEmotions makeObjectsPerformSelector:@selector(setFolder:) withObject:@"lxh"];
}
return _lxhEmotions;
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/06 - LittleProject(小项目展示)/02 - EmotionsKeyboard/Classes/Tool/SYEmotionTool.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 396 |
```objective-c
//
// SYEmotionTool.h
// 01 -
//
// Created by apple on 15-1-30.
//
#import <Foundation/Foundation.h>
@interface SYEmotionTool : NSObject
/**
* (, HWEmotion)
*/
+ (NSArray *)defaultEmotions;
/**
* (, HWEmotion)
*/
+ (NSArray *)recentEmotions;
/**
* (, HWEmotion)
*/
+ (NSArray *)lxhEmotions;
@end
``` | /content/code_sandbox/BigShow1949/Classes/06 - LittleProject(小项目展示)/02 - EmotionsKeyboard/Classes/Tool/SYEmotionTool.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 102 |
```objective-c
//
// SYComposeViewController.m
// 01 -
//
// Created by apple on 15-1-30.
//
#define SYEmotionButtonDidClickNotification @"SYEmotionButtonDidClickNotification"
#import "SYComposeViewController.h"
#import "SYTextView.h"
#import "SYEmotionKeyboard.h"
#import "MJExtension.h"
#import "SYEmotion.h"
@interface SYComposeViewController () <UITextViewDelegate>
@property (nonatomic, weak) SYTextView *textView;
@end
@implementation SYComposeViewController
- (void)viewDidLoad {
[super viewDidLoad];
//
[self setNav];
//
[self setupTextView];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.navigationItem.rightBarButtonItem.enabled = NO;
}
/**
*
*/
- (void)setupTextView
{
// emoji
SYTextView *textView = [[SYTextView alloc] init];
textView.placehoder = @"";
textView.frame = self.view.bounds;
textView.font = [UIFont systemFontOfSize:20];
textView.delegate = self;
[self.view addSubview:textView];
self.textView = textView;
//
SYEmotionKeyboard *keyboard = [[SYEmotionKeyboard alloc] init];
keyboard.height = 216;
textView.inputView = keyboard;
//
[[NSNotificationCenter defaultCenter] addObserverForName:@"SYDeleteButtonDidClickNotification" object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
[textView deleteBackward];
}];
//
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(emotionButtonClick:) name:SYEmotionButtonDidClickNotification object:nil];
}
- (void)emotionButtonClick:(NSNotification *)note
{
//
SYEmotion *emotion = note.userInfo[@"SYClickedEmotion"];
NSString *name = [NSString stringWithFormat:@"%@/%@", emotion.folder, emotion.png];
//
NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
attachment.image = [UIImage imageNamed:name];
CGFloat imgWH = self.textView.font.lineHeight;
attachment.bounds = CGRectMake(0, -4, imgWH, imgWH);
NSAttributedString *imageString = [NSAttributedString attributedStringWithAttachment:attachment];
//
NSUInteger oldLoc = self.textView.selectedRange.location;
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] init];
[string appendAttributedString:self.textView.attributedText];
// [string insertAttributedString:imageString atIndex:oldLoc];
[string replaceCharactersInRange:self.textView.selectedRange withAttributedString:imageString];
// textViewfont\textColor(text)
// (attributedText)\, addAttribute
[string addAttribute:NSFontAttributeName value:self.textView.font range:NSMakeRange(0, string.length)];
// ,
self.textView.attributedText = string;
//
self.textView.selectedRange = NSMakeRange(oldLoc + 1, 0);
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
/**
*
*/
- (void)setNav
{
// UIBarButtonItem
UIBarButtonItem *item = [UIBarButtonItem appearance];
[item setTitleTextAttributes:@{
NSForegroundColorAttributeName : [UIColor orangeColor]
} forState:UIControlStateNormal];
[item setTitleTextAttributes:@{
NSForegroundColorAttributeName : [UIColor lightGrayColor]
} forState:UIControlStateDisabled];
// clearColor
self.view.backgroundColor = [UIColor whiteColor];
//
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:self action:@selector(cancel)];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:self action:@selector(send)];
//
self.title = @"";
}
/**
*
*/
- (void)cancel
{
[self dismissViewControllerAnimated:YES completion:nil];
}
/**
*
*/
- (void)send
{
}
#pragma mark - <UITextViewDelegate>
- (void)textViewDidChange:(UITextView *)textView
{
self.navigationItem.rightBarButtonItem.enabled = textView.hasText;
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/06 - LittleProject(小项目展示)/02 - EmotionsKeyboard/Classes/Controller/SYComposeViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 847 |
```objective-c
//
// YFCard.h
// Jigsaw
//
// Created by apple on 16/8/27.
//
#import <UIKit/UIKit.h>
//typedef struct{
// int X;
// int Y;
//};
//typedef struct Position position;
//
//
//CG_INLINE Position
//PointMake(CGFloat x, CGFloat y) {
// CGPoint p;
// p.x = x;
// p.y = y;
// return p;
//}
struct CardPosition{
int X;
int Y;
};
typedef struct CardPosition Position;
CG_INLINE Position
PositionMake(int X, int Y)
{
Position position;
position.X = X;
position.Y = Y;
return position;
}
@interface YFCard : UIImageView
- (void)moveToTarget:(id)target action:(SEL)action;
- (void)setDefaultFrame;
//
@property (nonatomic, assign) Position originPosition;
//
@property (nonatomic, assign) Position position;
@end
``` | /content/code_sandbox/BigShow1949/Classes/06 - LittleProject(小项目展示)/Jigsaw/YFCard.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 211 |
```objective-c
//
// YFChessBoardView.h
// Jigsaw
//
// Created by apple on 16/8/27.
//
#import <UIKit/UIKit.h>
//
@interface YFChessBoardView : UIImageView
@property (nonatomic, strong) UIImage *backgroundImage;
- (void)randomBreak;
@end
``` | /content/code_sandbox/BigShow1949/Classes/06 - LittleProject(小项目展示)/Jigsaw/YFChessBoardView.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 68 |
```objective-c
//
// YFCard.m
// Jigsaw
//
// Created by apple on 16/8/27.
//
#import "YFCard.h"
@implementation YFCard
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.userInteractionEnabled = YES;
}
return self;
}
- (void)setDefaultFrame {
CGRect tempF = self.frame;
tempF.origin.x = self.position.X * tempF.size.width;
tempF.origin.y = self.position.Y * tempF.size.height;
self.frame = tempF;
}
///**
// * position
// */
//- (void)setPosition:(Position)position {
//
// _position = position;
//
// CGRect tempF = self.frame;
// tempF.origin.x = position.X * tempF.size.width;
// tempF.origin.y = position.Y * tempF.size.height;
// self.frame = tempF;
//}
- (void)moveToTarget:(id)target action:(SEL)action {
[UIView animateWithDuration:0.2f animations:^{
CGRect f = self.frame;
f.origin.x = self.position.X * self.frame.size.width;
f.origin.y = self.position.Y * self.frame.size.height;
self.frame=f;
} completion:^(BOOL finished) {
if (target) {
[target performSelector:action];
}
}];
}
- (NSString *)description {
return [NSString stringWithFormat:@"x:%d, y:%zd", self.position.X, self.position.Y];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/06 - LittleProject(小项目展示)/Jigsaw/YFCard.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 335 |
```objective-c
//
// YFJigsawViewController.h
// Jigsaw
//
// Created by apple on 16/8/28.
//
#import <UIKit/UIKit.h>
@interface YFJigsawViewController : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/06 - LittleProject(小项目展示)/Jigsaw/YFJigsawViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 48 |
```objective-c
//
// YFJigsawViewController.m
// Jigsaw
//
// Created by apple on 16/8/28.
//
#import "YFJigsawViewController.h"
#import "YFChessBoardView.h"
@interface YFJigsawViewController ()
@property (nonatomic, strong) YFChessBoardView *boardView;
@end
@implementation YFJigsawViewController
- (void)viewDidLoad {
self.view.backgroundColor = [UIColor whiteColor];
YFChessBoardView *boardView = [[YFChessBoardView alloc] initWithFrame:CGRectMake(0, 0, 280, 280)];;
boardView.center = self.view.center;
boardView.backgroundImage = [UIImage imageNamed:@"img1.jpg"];
[self.view addSubview:boardView];
self.boardView = boardView;
//
UIButton *breakBtn = [[UIButton alloc] init];
breakBtn.frame = CGRectMake(30, CGRectGetMaxY(boardView.frame) + 20, 100, 44);
[breakBtn setTitle:@" " forState:UIControlStateNormal];
[breakBtn addTarget:self action:@selector(breakBtnClick:) forControlEvents:UIControlEventTouchUpInside];
breakBtn.backgroundColor = [UIColor redColor];
[self.view addSubview:breakBtn];
[self breakBtnClick:breakBtn];
}
- (void)breakBtnClick:(UIButton *)btn {
[self.boardView randomBreak];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/06 - LittleProject(小项目展示)/Jigsaw/YFJigsawViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 291 |
```objective-c
//
// YFChessBoardView.m
// Jigsaw
//
// Created by apple on 16/8/27.
//
#import "YFChessBoardView.h"
#import "UIColor+Extension.h"
#import "YFCard.h"
typedef enum{
DIR_NONE = 0,
DIR_LEFT,
DIR_UP,
DIR_RIGHT,
DIR_DOWN,
}Direction;
YFCard* cardsMap[4][4];
Position nullPosition;
@interface YFChessBoardView ()
@property (nonatomic, strong) NSMutableArray *originArr;
@end
@implementation YFChessBoardView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
NSLog(@"frame = %@", NSStringFromCGRect(frame));
self.backgroundColor = [UIColor colorWithRGBRed:246 green:246 blue:246];
self.userInteractionEnabled = YES;
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
//
[self setPartitionLine];
}
- (void)setBackgroundImage:(UIImage *)backgroundImage {
_backgroundImage = backgroundImage;
CGFloat picWH = self.frame.size.height/4;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (i < 4-1 || j < 4-1) { // (3,3)
CGRect rect =CGRectMake(picWH*i, picWH*j, picWH, picWH);
YFCard *card = [[YFCard alloc] initWithImage:[[UIImage alloc] initWithCGImage:CGImageCreateWithImageInRect(backgroundImage.CGImage, rect)]];
card.position = PositionMake(i, j);
card.originPosition = PositionMake(i, j);
[card setDefaultFrame];
[self addSubview:card];
cardsMap[i][j]=card;
}
}
}
//
nullPosition = PositionMake(4-1, 4-1);
cardsMap[nullPosition.X][nullPosition.Y] = nil;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
UITouch * touch = [[touches allObjects] objectAtIndex:0];
CGPoint p = [touch locationInView:self];
CGFloat picWH = self.frame.size.height/4;
int x = p.x/picWH;
int y = p.y/picWH;
YFCard *card = cardsMap[x][y];
switch ([self getDirectionWithCard:card]) {
case DIR_LEFT:
[self moveCard:card toPosition:PositionMake(x-1, y)];
[self checkSuccess];
break;
case DIR_UP:
[self moveCard:card toPosition:PositionMake(x, y-1)];
[self checkSuccess];
break;
case DIR_RIGHT:
[self moveCard:card toPosition:PositionMake(x+1, y)];
[self checkSuccess];
break;
case DIR_DOWN:
[self moveCard:card toPosition:PositionMake(x, y+1)];
[self checkSuccess];
break;
default:
break;
}
}
- (void)moveCard:(YFCard *)card toPosition:(Position)position {
cardsMap[card.position.X][card.position.Y] = nil;
nullPosition = card.position;
cardsMap[position.X][position.Y] = card;
card.position = position;
[card moveToTarget:nil action:nil];
}
-(BOOL)checkSuccess{
BOOL success = YES;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (cardsMap[i][j]) {
YFCard *card = cardsMap[i][j];
if (card.originPosition.X != card.position.X ||
card.originPosition.Y != card.position.Y) {
success = NO;
}
}
}
}
if (success) {
[[[UIAlertView alloc] initWithTitle:@"" message:@"" delegate:self cancelButtonTitle:@"" otherButtonTitles:nil, nil] show];
}
return success;
}
-(Direction)getDirectionWithCard:(YFCard *)touchedCard {
int x = touchedCard.position.X; // 2
int y = touchedCard.position.Y; // 3 (y,x)--->(3,2)
// , 0<index<4
if (x>0 && !cardsMap[x-1][y]) { //
return DIR_LEFT;
}
if (x<4-1 && !cardsMap[x+1][y]) { //
return DIR_RIGHT;
}
if (y>0 && !cardsMap[x][y-1]) { //
return DIR_UP;
}
if (y<4-1 && !cardsMap[x][y+1]) { //
return DIR_DOWN;
}
return DIR_NONE;
}
#pragma mark -
- (void)setPartitionLine {
//
CGFloat padding = self.frame.size.height/4.f;
for (int i = 0; i <= 4; i++) {
[self addLineWithFrame:CGRectMake(0, padding * i, self.frame.size.height, 1)];
}
for (int j = 0; j <= 4; j++) {
[self addLineWithFrame:CGRectMake(padding * j, 0, 1, self.frame.size.height)];
}
}
- (void)addLineWithFrame:(CGRect)frame {
UIView *line = [[UIView alloc] initWithFrame:frame];
line.backgroundColor = [UIColor blackColor];
[UIColor colorWithRGBRed:255 green:255 blue:255];
[self addSubview:line];
}
#pragma mark -
- (void)randomBreak {
for (int i = 0; i < 1000; i++) {
Direction dir = [self getValidRandomDirect];;
int x = nullPosition.X;
int y = nullPosition.Y;
switch (dir) {
case DIR_LEFT:
x--;
break;
case DIR_UP:
y--;
break;
case DIR_RIGHT:
x++;
break;
case DIR_DOWN:
y++;
break;
default:
break;
}
YFCard *card = cardsMap[x][y];
[self moveCard:card toPosition:nullPosition];
cardsMap[x][y] = nil;
}
}
#pragma mark - private
- (Direction)getValidRandomDirect {
Direction dir = arc4random_uniform(5);
switch (dir) {
case DIR_LEFT:
if (nullPosition.X-1 == -1) {
return [self getValidRandomDirect];
}
break;
case DIR_UP:
if (nullPosition.Y-1 == -1) {
return [self getValidRandomDirect];
}
break;
case DIR_RIGHT:
if (nullPosition.X+1 == 4) {
return [self getValidRandomDirect];
}
break;
case DIR_DOWN:
if (nullPosition.Y+1 == 4) {
return [self getValidRandomDirect];
}
break;
default:
return [self getValidRandomDirect];
break;
}
return dir;
}
#pragma mark -
- (NSMutableArray *)originArr {
if (!_originArr) {
_originArr = [NSMutableArray array];
}
return _originArr;
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/06 - LittleProject(小项目展示)/Jigsaw/YFChessBoardView.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 1,632 |
```objective-c
//
// YFKnowledgeViewController.m
// BigShow1949
//
// Created by on 15-9-1.
//
#import "YFKnowledgeViewController.h"
@implementation YFKnowledgeViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setupDataArr:@[@[@"Masonry",@"YFMasonryDemoViewController_UIStoryboard"],
@[@"",@"YFLifeCycleViewController"],
@[@"",@"YFResponderChainViewController"],
@[@"",@"YFGuideViewController"],
@[@"",@"YFRunTimeViewController"],
@[@"",@"YFNotificationCenterVC"],
@[@"",@"YFStatisticalCodeViewController"],
@[@"GCD",@"GCDViewController"],
@[@"KVC",@"KVCViewController"],
@[@"",@"QRCodeViewController"],
@[@"",@"MultipleInheritanceViewController"],
@[@"Quartz2D",@"YFQuartz2DViewController"],
@[@"JS",@"JSViewController"]
]];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/YFKnowledgeViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 204 |
```objective-c
//
// YFKnowledgeViewController.h
// BigShow1949
//
// Created by on 15-9-1.
//
#import <UIKit/UIKit.h>
@interface YFKnowledgeViewController : BaseTableViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/YFKnowledgeViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 50 |
```objective-c
//
// UIViewA.h
// 77-
//
// Created by zhht01 on 16/3/21.
//
#import <UIKit/UIKit.h>
@interface UIViewA : UIView
@property (nonatomic, strong) UIButton *buttonA;
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/ResponderChain/UIViewA.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 55 |
```objective-c
//
// UIViewB.m
// 77-
//
// Created by zhht01 on 16/3/21.
//
#import "UIViewB.h"
@implementation UIViewB
#pragma mark - touches
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"B - touchesBeagan..");
// ViewViewController
[self.nextResponder touchesBegan:touches withEvent:event];
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"B - touchesCancelled..");
// ViewViewController
[self.nextResponder touchesCancelled:touches withEvent:event];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"B - touchesEnded..");
// ViewViewController
[self.nextResponder touchesEnded:touches withEvent:event];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"B - touchesMoved..");
// ViewViewController
[self.nextResponder touchesMoved:touches withEvent:event];
}
/*
:
viewA
buttonA
viewB
buttonB
*/
// 3ViewBButtonB
// ViewBViewB.UserInteractionEnable=NOoverrideViewBponitInside
/*
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
// View
return NO;
}
*/
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/ResponderChain/UIViewB.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 312 |
```objective-c
//
// YFResponderChainViewController.m
// BigShow1949
//
// Created by zhht01 on 16/4/13.
//
#import "YFResponderChainViewController.h"
#import "UIViewA.h"
#import "UIViewB.h"
@interface YFResponderChainViewController ()
@end
@implementation YFResponderChainViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
/*
:
viewA
buttonA
viewB
buttonB
*/
/*
:
1)ButtonAButtonB
2ViewAViewBtouches
3ViewBButtonB
*/
// viewA
UIViewA *viewA = [[UIViewA alloc] initWithFrame:CGRectMake(0, 64, 320, 400)];
viewA.backgroundColor = [UIColor lightGrayColor];
[self.view addSubview:viewA];
// buttonA
UIButton *buttonA = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
viewA.buttonA = buttonA;
buttonA.backgroundColor = [UIColor redColor];
[buttonA addTarget:self action:@selector(buttonAClick:) forControlEvents:UIControlEventTouchUpInside];
[viewA addSubview:buttonA];
// viewB
UIViewB *viewB = [[UIViewB alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
viewB.backgroundColor = [UIColor greenColor];
viewB.alpha = 0.4; // + , buttonA
[viewA addSubview:viewB];
// buttonB
UIButton *buttonB = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
buttonB.backgroundColor = [UIColor blueColor];
[buttonB addTarget:self action:@selector(buttonBClick:) forControlEvents:UIControlEventTouchUpInside];
[viewB addSubview:buttonB];
}
- (void)buttonAClick:(UIButton *)button {
NSLog(@"buttonA----");
}
- (void)buttonBClick:(UIButton *)button {
NSLog(@"buttonB----");
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/ResponderChain/YFResponderChainViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 451 |
```objective-c
//
// UIViewB.h
// 77-
//
// Created by zhht01 on 16/3/21.
//
#import <UIKit/UIKit.h>
@interface UIViewB : UIView
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/ResponderChain/UIViewB.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 44 |
```objective-c
//
// YFResponderChainViewController.h
// BigShow1949
//
// Created by zhht01 on 16/4/13.
//
#import <UIKit/UIKit.h>
@interface YFResponderChainViewController : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/ResponderChain/YFResponderChainViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 52 |
```objective-c
//
// YFRunTimeViewController.h
// BigShow1949
//
// Created by on 16/7/6.
//
#import "BaseTableViewController.h"
@interface YFRunTimeViewController : BaseTableViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/RunTime/YFRunTimeViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 53 |
```objective-c
//
// YFRunTimeViewController.m
// BigShow1949
//
// Created by on 16/7/6.
//
#import "YFRunTimeViewController.h"
@interface YFRunTimeViewController ()
@end
@implementation YFRunTimeViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setupDataArr:@[@[@"",@"YFDictToModelViewController"],
@[@"",@"YFCategoryAttributeViewController"],
@[@"",@"YFAddMethodViewController"],
@[@"()",@"YFExchangeMethodVC"],
@[@"()",@"YFMultipleClicksViewController"],
@[@"",@"MsgForwardingViewController"],]];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/RunTime/YFRunTimeViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 143 |
```objective-c
//
// Car_Msg.h
// BigShow1949
//
// Created by apple on 16/11/28.
//
#import <Foundation/Foundation.h>
@interface Car_Msg : NSObject
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/RunTime/MessageForwarding/Car_Msg.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 44 |
```objective-c
//
// UIViewA.m
// 77-
//
// Created by zhht01 on 16/3/21.
//
#import "UIViewA.h"
@implementation UIViewA
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
}
return self;
}
- (void)buttonAClick:(UIButton *)button {
NSLog(@"buttonA----");
}
/*
:
viewA
buttonA
viewB
buttonB
*/
// 1ButtonAButtonB
// ViewBButtonAButtonAViewViewAhitTesttouch pointButtonAButtonA
#pragma mark - hitTest
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
// touch point_btnhitTest_btn
CGPoint btnPointInA = [self.buttonA convertPoint:point fromView:self];
if ([self.buttonA pointInside:btnPointInA withEvent:event]) {
return self.buttonA;
}
//
return [super hitTest:point withEvent:event];
}
/*
:
viewA
buttonA
viewB
buttonB
*/
// 2ViewAViewBtouches
// ViewBoverridetouchesViewViewA
#pragma mark - touches
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"A - touchesBeagan..");
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"A - touchesCancelled..");
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"A - touchesEnded..");
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"A - touchesMoved..");
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/ResponderChain/UIViewA.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 399 |
```objective-c
//
// MsgForwardingViewController.h
// BigShow1949
//
// Created by apple on 16/11/28.
//
#import <UIKit/UIKit.h>
@interface MsgForwardingViewController : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/RunTime/MessageForwarding/MsgForwardingViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 48 |
```objective-c
//
// Person_Msg.h
// BigShow1949
//
// Created by apple on 16/11/28.
//
#import <Foundation/Foundation.h>
@interface Person_Msg : NSObject
- (void)run;
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/RunTime/MessageForwarding/Person_Msg.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 50 |
```objective-c
//
// Car_Msg.m
// BigShow1949
//
// Created by apple on 16/11/28.
//
#import "Car_Msg.h"
@implementation Car_Msg
- (void)run
{
NSLog(@"Car:%@ %s", self, sel_getName(_cmd));
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/RunTime/MessageForwarding/Car_Msg.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 67 |
```objective-c
//
// MsgForwardingViewController.m
// BigShow1949
//
// Created by apple on 16/11/28.
//
#import "MsgForwardingViewController.h"
#import "Person_Msg.h"
@interface MsgForwardingViewController ()
@end
@implementation MsgForwardingViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Person run, Personrun
// ,[per run]
Person_Msg *per = [[Person_Msg alloc] init];
[per run];
}
- (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
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/RunTime/MessageForwarding/MsgForwardingViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 191 |
```objective-c
//
// YFAddMethodViewController.m
// BigShow1949
//
// Created by apple on 16/10/28.
//
#import "YFAddMethodViewController.h"
#import "YFPerson.h"
@interface YFAddMethodViewController ()
@end
@implementation YFAddMethodViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
/*
,,,,.
*/
YFPerson *p = [[YFPerson alloc] init];
// personeatperformSelector
//
[p performSelector:@selector(eat)];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/RunTime/AddMethod/YFAddMethodViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 133 |
```objective-c
//
// Person_Msg.m
// BigShow1949
//
// Created by apple on 16/11/28.
//
#import "Person_Msg.h"
#import <objc/runtime.h>
#import "Car_Msg.h"
@implementation Person_Msg
/**
* crash,crash
+ (BOOL)resolveInstanceMethod:(SEL)sel
+ (BOOL)resolveClassMethod:(SEL)sel
- (id)forwardingTargetForSelector:(SEL)aSelector
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector;
- (void)forwardInvocation:(NSInvocation *)anInvocation;
*/
void run (id self, SEL _cmd)
{
// C
NSLog(@"person:%@ %s", self, sel_getName(_cmd));
}
/**
*
* (Dynamic Method ResolutionLazy method resolution):(Class)resolveInstanceMethod:(resolveClassMethod:)YES,
* Personrun, run, resolveInstanceMethod
*/
//+ (BOOL)resolveInstanceMethod:(SEL)sel {
//
// if(sel == @selector(run)) {
// NSLog(@"======1");
// class_addMethod([self class], sel, (IMP)run, "v@:");
// return YES;
// }
// return [super respondsToSelector:sel];
//}
/**
* (Fast forwarding path):targetforwardingTargetForSelector:,nilself
* , , forwardingTargetForSelector
*/
//- (id)forwardingTargetForSelector:(SEL)aSelector {
// NSLog(@"======2");
// return [[Car_Msg alloc] init];
//}
/**
* forwardingTargetForSelector,
methodSignatureForSelector forwardInvocation
*/
/**
*
* (Normal forwarding path):runtimemethodSignatureForSelector:SelectorruntimeNSInvocationforwardInvocation:NSInvocationmethodSignatureForSelector:doesNotRecognizeSelector:,
*
* unrecognized selector sent to instancemethodSignatureForSelectorrun
forwardInvocation
*/
/**
* methodSignatureForSelector
* , forwardInvocationNSInvocation
*
*/
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
{
NSString *sel = NSStringFromSelector(aSelector);
// SEL
if ([sel isEqualToString:@"run"]) {
//
return [NSMethodSignature signatureWithObjCTypes:"v@:"];
}
return [super methodSignatureForSelector:aSelector];
}
/**
* "v@:", , self, _cmd
self , _cmd SEL, , ,
vvoid, @self, :_cmd
*/
-(void)forwardInvocation:(NSInvocation *)anInvocation
{
SEL selector = [anInvocation selector];
//
Car_Msg *car = [[Car_Msg alloc] init];
if ([car respondsToSelector:selector]) {
//
[anInvocation invokeWithTarget:car];
}
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/RunTime/MessageForwarding/Person_Msg.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 598 |
```objective-c
//
// YFAddMethodViewController.h
// BigShow1949
//
// Created by apple on 16/10/28.
//
#import <UIKit/UIKit.h>
@interface YFAddMethodViewController : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/RunTime/AddMethod/YFAddMethodViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 50 |
```objective-c
//
// YFPerson.m
// BigShow1949
//
// Created by zhht01 on 16/4/14.
//
#import "YFPerson.h"
#import <objc/runtime.h>
@implementation YFPerson
-(void)run{
NSLog(@"%s",__func__);
}
/*------------------- KVC ----------------------------*/
+ (instancetype)personWithDict:(NSDictionary *)dict
{
YFPerson *person = [[self alloc] init];
[person setValuesForKeysWithDictionary:dict];
return person;
}
- (void)setValue:(id)value forUndefinedKey:(NSString *)key
{
NSLog(@"value = %@, key = %@", value, key);
if ([key isEqualToString:@"userName"]) {
self.name = value;
}
}
/*------------------------ ------------------------------*/
/**
self_cmd,
self
_cmd
*/
// void(*)()
//
void test_eat(id self,SEL sel)
{
NSLog(@"eat, test_eat");
}
// ,.
//
+ (BOOL)resolveInstanceMethod:(SEL)sel
{
if (sel == @selector(eat)) {
// eat
//
//
//
// (+) v:void @:->self :SEL->_cmd
class_addMethod(self, @selector(eat), test_eat, "v@:");
}
return [super resolveInstanceMethod:sel];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/RunTime/CategoryAttribute/YFPerson.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 307 |
```objective-c
//
// YFCategoryAttributeViewController.m
// BigShow1949
//
// Created by zhht01 on 16/4/14.
//
#import "YFCategoryAttributeViewController.h"
#import "YFPerson+addproty.m"
#import "UILabel+Associate.h"
@interface YFCategoryAttributeViewController ()
@end
@implementation YFCategoryAttributeViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
// 1
YFPerson *person = [[YFPerson alloc] init];
person.name = @"";
person.addr = @"";
NSLog(@" addr = %@", person.addr);
[person run];
// 2
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
label.flashColor = [UIColor blueColor];
NSLog(@"flashColor = %@", label.flashColor);
[self.view addSubview:label];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/RunTime/CategoryAttribute/YFCategoryAttributeViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 205 |
```objective-c
//
// UILabel+Associate.m
// BigShow1949
//
// Created by zhht01 on 16/4/15.
//
#import "UILabel+Associate.h"
@implementation UILabel (Associate)
static char flashColorKey;
- (void)setFlashColor:(UIColor *)flashColor {
self.backgroundColor = flashColor;
objc_setAssociatedObject(self, &flashColorKey, flashColor, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
// objc_setAssociatedObject(<#id object#>, <#const void *key#>, <#id value#>, <#objc_AssociationPolicy policy#>)
}
- (UIColor *)flashColor {
return objc_getAssociatedObject(self, &flashColorKey);
// objc_getAssociatedObject(<#id object#>, <#const void *key#>)
}
/*
keykeyconst void *keyflashColorKeysetAssocaitedObjectflashColorKeygetnil&flashColorKey
*/
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/RunTime/CategoryAttribute/UILabel+Associate.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 204 |
```objective-c
//
// YFPerson+addproty.h
// BigShow1949
//
// Created by zhht01 on 16/4/14.
//
#import "YFPerson.h"
@interface YFPerson (addproty)
@property(nonatomic, copy)NSString *addr;
-(void)saySex;
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/RunTime/CategoryAttribute/YFPerson+addproty.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 69 |
```objective-c
//
// YFPerson.h
// BigShow1949
//
// Created by zhht01 on 16/4/14.
//
#import <Foundation/Foundation.h>
@interface YFPerson : NSObject
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *age;
-(void)run;
+ (instancetype)personWithDict:(NSDictionary *)dict;
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/RunTime/CategoryAttribute/YFPerson.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 85 |
```objective-c
//
// YFCategoryAttributeViewController.h
// BigShow1949
//
// Created by zhht01 on 16/4/14.
//
#import <UIKit/UIKit.h>
@interface YFCategoryAttributeViewController : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/RunTime/CategoryAttribute/YFCategoryAttributeViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 52 |
```objective-c
//
// UILabel+Associate.h
// BigShow1949
//
// Created by zhht01 on 16/4/15.
//
#import <UIKit/UIKit.h>
#import <objc/runtime.h>
@interface UILabel (Associate)
- (void)setFlashColor:(UIColor *)flashColor;
- (UIColor *)flashColor;
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/RunTime/CategoryAttribute/UILabel+Associate.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 71 |
```objective-c
//
// YFDictToModelViewController.m
// BigShow1949
//
// Created by on 16/7/6.
//
#import "YFDictToModelViewController.h"
#import "Person.h"
#import "YFPerson.h"
@interface YFDictToModelViewController ()
@property (nonatomic, strong) NSMutableArray *dataArr;
@end
@implementation YFDictToModelViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.dataArr = [NSMutableArray array];
NSArray *dictArr = @[@{@"name" : @"Jack",
@"userId" : @"11111",
@"classes" : @{@"className" : @"Chinese", @"time" : @"2016_03"},
@"teachers" : @[@{@"teaName" : @"Lisa1", @"teaAge" : @"21"},
@{@"teaName" : @"Lisa2", @"teaAge" : @"22"},
@{@"teaName" : @"Lisa3", @"teaAge" : @"23"}]},
@{@"name" : @"Rose",
@"userId" : @"22222",
@"classes" : @{@"className" : @"Math", @"time" : @"2016_04"},
@"teachers" : @[@{@"teaName" : @"Lisa1", @"teaAge" : @"21"},
@{@"teaName" : @"Lisa2", @"teaAge" : @"22"},
@{@"teaName" : @"Lisa3", @"teaAge" : @"23"}]}];
for (NSDictionary *dict in dictArr) {
Person *p = [Person modelWithDict:dict];
[self.dataArr addObject:p];
}
NSLog(@"dataArr = %@", self.dataArr);
[self KVCtoModel];
[self printValue];
}
// VC
- (void)KVCtoModel {
NSDictionary *dict = @{@"userName" : @"jack",
@"age" : @"12"};
YFPerson *person = [YFPerson personWithDict:dict];
NSLog(@"name = %@, age = %@", person.name, person.age);
}
//
- (void)printValue {
//
NSDictionary *dict = @{@"name" : @"jack",
@"age" : @"12"};
[Model resolveDict:dict];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/RunTime/DictToModel/YFDictToModelViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 496 |
```objective-c
//
// YFPerson+addproty.m
// BigShow1949
//
// Created by zhht01 on 16/4/14.
//
#import "YFPerson+addproty.h"
#import <objc/runtime.h>
@implementation YFPerson (addproty)
static char const *strAddrKey = "strAddrKey";
- (NSString *)addr
{
// key,zhi
return objc_getAssociatedObject(self, strAddrKey);
}
- (void)setAddr:(NSString *)addr
{
/*
OBJC_ASSOCIATION_ASSIGN; //assign
OBJC_ASSOCIATION_COPY_NONATOMIC; //copy
OBJC_ASSOCIATION_RETAIN_NONATOMIC; // retain
OBJC_ASSOCIATION_RETAIN;
OBJC_ASSOCIATION_COPY;
*/
/*
objc_setAssociatedObject(id object, const void *key, id value, objc_AssociationPolicy policy);
:
1) id object
2) const void *key key
3) id value value
4) objc_AssociationPolicy policy copyretainassignNONATOMIC
*/
objc_setAssociatedObject(self, strAddrKey, addr, OBJC_ASSOCIATION_COPY_NONATOMIC);
}
-(void)saySex{
NSLog(@"%s----%@",__func__,self);
}
/*
@property_gettersetter,
-(NSString *)addr{
return @"addr";
}
-(void)setAddr:(NSString *)addr{
}
runtime
*/
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/RunTime/CategoryAttribute/YFPerson+addproty.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 327 |
```objective-c
//
// Person.h
// Cocopods
//
// Created by on 16/7/6.
//
#import "Model.h"
#import "Classes.h"
#import "Teacher.h"
@interface Person : Model
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSString *userId;
@property (nonatomic, strong) Classes *classes; // ()
@property (nonatomic, strong) Teacher *teachers; //
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/RunTime/DictToModel/Person.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 94 |
```objective-c
//
// Model.m
// Cocopods
//
// Created by on 16/7/6.
//
#import "Model.h"
#import "objc/runtime.h"
@implementation Model
+ (instancetype)modelWithDict:(NSDictionary *)dict {
id objc = [[self alloc] init];
unsigned int count;
//
Ivar *ivarList = class_copyIvarList(self, &count);
for (int i = 0; i < count; i++) {
//
Ivar ivar = ivarList[i];
//
NSString *name = [NSString stringWithUTF8String:ivar_getName(ivar)];
// ->key
//
NSString *key = [name substringFromIndex:1];
// value
id value = dict[key];
// :
// value
if ([value isKindOfClass:[NSDictionary class]]) {
//
// modelWithDict
//
//
NSString *type = [NSString stringWithUTF8String:ivar_getTypeEncoding(ivar)];
//
NSRange range = [type rangeOfString:@"\""];
type = [type substringFromIndex:range.location + range.length];
range = [type rangeOfString:@"\""];
//
type = [type substringToIndex:range.location];
//
Class modelClass = NSClassFromString(type);
NSLog(@"modelClass = %@", modelClass);
if (modelClass) { //
//
value = [modelClass modelWithDict:value];
}
}
// NSArray.
//
if ([value isKindOfClass:[NSArray class]]) {
//
if ([self respondsToSelector:@selector(arrayContainModelClass)]) {
// id
id idSelf = self;
//
NSString *type = [idSelf arrayContainModelClass][key];
//
Class classModel = NSClassFromString(type);
NSMutableArray *arrM = [NSMutableArray array];
//
for (NSDictionary *dict in value) {
//
id model = [classModel modelWithDict:dict];
[arrM addObject:model];
}
// value
value = arrM;
}
}
if (value) { //
// KVC
[objc setValue:value forKey:key];
}
}
free(ivarList);
return objc;
}
+ (id)arrayContainModelClass {
NSMutableDictionary *dictM = [[NSMutableDictionary alloc] init];
unsigned int count;
objc_property_t *properties = class_copyPropertyList([self class], &count);
for(int i = 0; i < count; i++)
{
objc_property_t property = properties[i];
NSString *key = [NSString stringWithFormat:@"%s", property_getName(property)];
NSString *value = [NSString stringWithFormat:@"%s", property_getAttributes(property)];
//
NSRange range = [value rangeOfString:@"\""];
value = [value substringFromIndex:range.location + range.length];
range = [value rangeOfString:@"\""];
value = [value substringToIndex:range.location];
[dictM setValue:value forKey:key];
}
free(properties);
return dictM;
}
//
+ (void)resolveDict:(NSDictionary *)dict{
//
NSMutableString *strM = [NSMutableString string];
// 1.key
[dict enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
//
NSString *type;
if ([obj isKindOfClass:NSClassFromString(@"__NSCFString")]) {
type = @"NSString";
}else if ([obj isKindOfClass:NSClassFromString(@"__NSCFArray")]){
type = @"NSArray";
}else if ([obj isKindOfClass:NSClassFromString(@"__NSCFNumber")]){
type = @"int";
}else if ([obj isKindOfClass:NSClassFromString(@"__NSCFDictionary")]){
type = @"NSDictionary";
}
//
NSString *str;
if ([type containsString:@"NS"]) {
str = [NSString stringWithFormat:@"@property (nonatomic, strong) %@ *%@;",type,key];
}else{
str = [NSString stringWithFormat:@"@property (nonatomic, assign) %@ %@;",type,key];
}
//
[strM appendFormat:@"\n%@\n",str];
}];
//
NSLog(@"%@",strM);
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/RunTime/DictToModel/Model.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 970 |
```objective-c
//
// Classes.m
// Cocopods
//
// Created by on 16/7/6.
//
#import "Classes.h"
@implementation Classes
- (NSString *)description {
return [NSString stringWithFormat:@"{className = %@, time = %@}", self.className , self.time];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/RunTime/DictToModel/Classes.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 66 |
```objective-c
//
// Classes.h
// Cocopods
//
// Created by on 16/7/6.
//
#import "Model.h"
@interface Classes : Model
@property (nonatomic, strong) NSString *className;
@property (nonatomic, strong) NSString *time;
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/RunTime/DictToModel/Classes.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 60 |
```objective-c
//
// Teacher.h
// Cocopods
//
// Created by on 16/7/6.
//
#import "Model.h"
@interface Teacher : Model
@property (nonatomic, strong) NSString *teaName;
@property (nonatomic, strong) NSString *teaAge;
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/RunTime/DictToModel/Teacher.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 62 |
```objective-c
//
// YFDictToModelViewController.h
// BigShow1949
//
// Created by on 16/7/6.
//
#import <UIKit/UIKit.h>
@interface YFDictToModelViewController : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/RunTime/DictToModel/YFDictToModelViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 52 |
```objective-c
//
// Person.m
// Cocopods
//
// Created by on 16/7/6.
//
#import "Person.h"
//#import "NSObject+Model.h"
@implementation Person
- (NSString *)description {
return [NSString stringWithFormat:@"name = %@, userId = %@, [classes = %@], [teachers = %@]", self.name, self.userId, self.classes, self.teachers];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/RunTime/DictToModel/Person.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 90 |
```objective-c
//
// Teacher.m
// Cocopods
//
// Created by on 16/7/6.
//
#import "Teacher.h"
@implementation Teacher
- (NSString *)description {
return [NSString stringWithFormat:@"{teaName = %@, teaAge = %@}", self.teaName , self.teaAge];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/RunTime/DictToModel/Teacher.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 73 |
```objective-c
//
// Model.h
// Cocopods
//
// Created by on 16/7/6.
//
#import <Foundation/Foundation.h>
@interface Model : NSObject
+ (instancetype)modelWithDict:(NSDictionary *)dict;
//
+ (void)resolveDict:(NSDictionary *)dict;
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/RunTime/DictToModel/Model.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 66 |
```objective-c
//
// YFExchangeMethodVC.m
// BigShow1949
//
// Created by on 16/7/6.
//
#import "YFExchangeMethodVC.h"
#import "UIImage+Image.h"
@interface YFExchangeMethodVC ()
@end
@implementation YFExchangeMethodVC
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
// ,
UIImageView *imgView1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 100, 100, 100)];
imgView1.image = [UIImage imageNamed:@"4_circl"]; // 4_circle
[self.view addSubview:imgView1];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/RunTime/ExchangeMethod/YFExchangeMethodVC.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 147 |
```objective-c
//
// UIImage+Image.h
// BigShow1949
//
// Created by on 16/7/6.
//
#import <UIKit/UIKit.h>
@interface UIImage (Image)
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/RunTime/ExchangeMethod/UIImage+Image.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 44 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.