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
//
// DataAlterFieldView.m
// BigShow1949
//
// Created by zhht01 on 16/4/21.
//
#import "DataAlterFieldView.h"
#import "LCCSqliteManager.h"
#import "LccCell.h"
#import "Define.h"
#import "DataEditView.h"
@interface DataAlterFieldView ()<DataEditViewDelegate>
{
//()
NSMutableArray *_attributes;
LCCSqliteManager *_manager;
DataEditView *_dataEditView;
}
@end
@implementation DataAlterFieldView
- (instancetype)initWithFrame:(CGRect)frame{
if (self = [super initWithFrame:frame]) {
//
_dataEditView = [[DataEditView alloc] initWithFrame:frame];
_dataEditView.delegate = self;
[self addSubview:_dataEditView];
}
return self;
}
- (void)setCellCount:(NSInteger)cellCount {
_cellCount = cellCount;
// cell
// _dataEditView.cellCount = self.cellCount;
NSMutableArray *placeholders = [NSMutableArray array];
for (NSInteger i = 0; i < cellCount; i++) {
NSString *placeholderStr = [NSString stringWithFormat:@"%zd:", i];
[placeholders addObject:placeholderStr];
}
_dataEditView.placeholders = placeholders;
[_dataEditView.tableView reloadData];
}
#pragma mark - DataEditViewDelegate
- (void)ensureAction:(NSArray *)dataArray {
// _attributes = [NSMutableArray array];
//
// NSLog(@"self.cellCount = %ld",(long)self.cellCount);
// for (int i = 0; i < self.cellCount; i ++) {
// NSIndexPath *path = [NSIndexPath indexPathForRow:i inSection:0];
// LccCell *pCell = [self.tableView cellForRowAtIndexPath:path ];
// NSLog(@"pcell = %@",pCell);
// if (pCell != nil&&[pCell.textFiled.text isEqualToString:@""]) {
// // [self.delegate insertError];
// return;
// }
// [_attributes addObject:pCell.textFiled.text];
// }
//
BOOL result = [[LCCSqliteManager shareInstance] addColumnToSheet:self.sheetTitle withAttributeArray:dataArray];
if (result == YES) {
NSLog(@"");
// [self _clear];
// [self.delegate insertSuccess];
[self.delegate alterFieldSuccess];
}
if (result == NO) {
NSLog(@"");
// [self.delegate insertError];
}
}
- (void)closeAction {
[self removeFromSuperview];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/12 - DataPersistence(数据持久化)/W3C/LCCSqliteManager/UI/DataList/DataAlterFieldView.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 567 |
```objective-c
//
// DataAlterFieldView.h
// BigShow1949
//
// Created by zhht01 on 16/4/21.
//
//
#import <UIKit/UIKit.h>
@protocol DataAlterFieldViewDelegate <NSObject>
//
- (void)alterFieldSuccess;
@end
@interface DataAlterFieldView : UIView
//cell
@property(nonatomic,assign)NSInteger cellCount;
//
@property(nonatomic,strong)NSString *sheetTitle;
@property(nonatomic,weak)id<DataAlterFieldViewDelegate>delegate;
//@property(nonatomic,strong)UITableView *tableView;
@end
``` | /content/code_sandbox/BigShow1949/Classes/12 - DataPersistence(数据持久化)/W3C/LCCSqliteManager/UI/DataList/DataAlterFieldView.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 116 |
```objective-c
//
// DataUpdateView.m
// DatabaseMangerDemo
//
// Created by LccLcc on 15/12/11.
//
#import "Define.h"
#import "DataUpdateView.h"
#import "LccCell.h"
#import "LCCSqliteManager.h"
#import "DataEditView.h"
@interface DataUpdateView () <DataEditViewDelegate>
{
// LCCSqliteManager *_manager;
DataEditView *_dataEditView;
}
@end
@implementation DataUpdateView
- (instancetype)initWithFrame:(CGRect)frame{
if (self = [super initWithFrame:frame]) {
_dataEditView = [[DataEditView alloc] initWithFrame:frame];
_dataEditView.delegate = self;
[self addSubview:_dataEditView];
}
return self;
}
- (void)setSheetTitle:(NSString *)sheetTitle {
_sheetTitle = sheetTitle;
_dataEditView.placeholders = [[LCCSqliteManager shareInstance] getSheetAttributesWithSheet:sheetTitle];
[_dataEditView.tableView reloadData];
}
- (void)setUpdateArray:(NSArray *)updateArray {
_updateArray = updateArray;
_dataEditView.texts = updateArray;
[_dataEditView.tableView reloadData];
//
//
NSArray *attributes = [[LCCSqliteManager shareInstance] getSheetAttributesWithSheet:self.sheetTitle];
//
self.updateCondition = @"";
for (int i = 0; i < attributes.count; i ++) {
if (i == attributes.count - 1) {
NSString *pstr = [NSString stringWithFormat:@" \"%@\"=\'%@\' ",attributes[i], updateArray[i]];
self.updateCondition = [self.updateCondition stringByAppendingString:pstr];
break;
}
NSString *pstr = [NSString stringWithFormat:@" \"%@\"=\'%@\' and", attributes[i], updateArray[i]];
self.updateCondition = [self.updateCondition stringByAppendingString:pstr];
}
NSLog(@"updateCondition = %@", self.updateCondition);
}
#pragma mark -DataEditViewDelegate
- (void)ensureAction:(NSArray *)dataArray {
NSLog(@" %@",dataArray);
NSLog(@"updateCondition = %@", self.updateCondition);
LCCSqliteManager *manger = [LCCSqliteManager shareInstance];
BOOL result = [manger updateDataToSheet:self.sheetTitle withData:dataArray where:self.updateCondition];
if (result == YES) {
[self.delegate updateSuccess];
}
if (result == NO) {
[self.delegate updateError];
}
}
- (void)closeAction {
[self removeFromSuperview];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/12 - DataPersistence(数据持久化)/W3C/LCCSqliteManager/UI/DataList/DataUpdateView.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 571 |
```objective-c
//
// SheetDataController.m
// DatabaseMangerDemo
//
// Created by LccLcc on 15/12/1.
//
#import "DataListController.h"
#import "LCCSqliteManager.h"
#import "LccButton.h"
#import "LccDataCell.h"
#import "DataInsertView.h"
#import "DataUpdateView.h"
#import "Define.h"
#import "DataAlterFieldView.h"
@interface DataListController ()<UITableViewDelegate,UITableViewDataSource,InsertViewDelegate,DataUpdateViewDelegate,DataAlterFieldViewDelegate>
{
//
LCCSqliteManager * _manager;
//
NSArray * _allDataArray;
//
DataInsertView * _dataInsertView;
//
DataAlterFieldView *_alterFieldView;
//
DataUpdateView * _dataUpdateView;
//
NSString * _searchCondition;
//
NSString * _deleateCondition;
//
NSString * _updateCondition;
//
UIAlertAction *_nextAction;
//
NSInteger _alterCount;
}
@end
@implementation DataListController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = self.sheetTitle;
[self setupNav];
_manager = [LCCSqliteManager shareInstance];
//
_attributesArray = [_manager getSheetAttributesWithSheet:self.sheetTitle];
//
_allDataArray = [_manager getSheetDataWithSheet:self.sheetTitle];
//
_deleateCondition = @"";
_updateCondition = @"";
_searchCondition = @"";
//
self.tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
[self.view addSubview:self.tableView];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
#pragma mark - TableViewDataSourse
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return _allDataArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 80;
}
#pragma mark - TableViewDelegate
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView * BGView = [[UIView alloc]init];
BGView.backgroundColor = [UIColor whiteColor];
long width2 = KWidth / 4;
long xOffset = (width2 - 45)/2;
NSArray *array = @[@"",@"",@"",@""];
for (int i = 0; i <= 3; i++) {
LccButton *button = [LccButton buttonWithType:UIButtonTypeCustom];
button.tag = i;
button.frame = CGRectMake(i*width2 + xOffset, 6, 45, 25);
[button setTitle:array[i] forState:UIControlStateNormal];
[button addTarget:self action:@selector(_buttonAction:) forControlEvents:UIControlEventTouchUpInside];
[BGView addSubview:button];
}
UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, 40, KWidth, 1)];
line.backgroundColor = [UIColor grayColor];
[BGView addSubview:line];
long width = KWidth/_attributesArray.count;
for (int i = 0; i < _attributesArray.count; i ++) {
UILabel *attributetitle = [[UILabel alloc]initWithFrame:CGRectMake(i * width, 50, width, 20)];
attributetitle.text = _attributesArray[i];
[attributetitle setFont:[UIFont fontWithName:@"Helvetica-Bold" size:14]];
attributetitle.textColor = [UIColor grayColor];
attributetitle.textAlignment = NSTextAlignmentCenter;
// if ([attributetitle.text isEqualToString:[_manager getSheetPrimaryKeyWithSheet:self.title]]) {
// attributetitle.textColor = [UIColor redColor];
// }
//
for (id object in [_manager getSheetPrimaryKeyWithSheet:self.title]) {
if ([attributetitle.text isEqualToString:object]) {
attributetitle.textColor = [UIColor redColor];
}
}
[BGView addSubview:attributetitle];
}
return BGView;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
LccDataCell *cell = [tableView dequeueReusableCellWithIdentifier:@"dataCell"];
// ,_allDataArray
// if (cell == nil) {
if (_allDataArray.count == 0) {
cell = [[LccDataCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"dataCell"];
}
else{
// NSArray *tempArray = _allDataArray[indexPath.row];
cell = [[LccDataCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"dataCell" data:_allDataArray[indexPath.row]];
}
// cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
// }
//,celltitle
for (int i = 0; i < _attributesArray.count; i ++) {
UILabel *pLabel = [cell viewWithTag:i+100];
pLabel.text = _allDataArray[indexPath.row][i];
}
return cell;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
LccDataCell *cell = [tableView cellForRowAtIndexPath:indexPath];
for (int i = 0; i < _attributesArray.count; i ++) {
UILabel *pLabel = [cell viewWithTag:i+100];
if (i == _attributesArray.count - 1) {
NSString *pstr = [NSString stringWithFormat:@" \"%@\"=\'%@\'",_attributesArray[i],pLabel.text];
_deleateCondition = [_deleateCondition stringByAppendingString:pstr];
break;
}
NSString *pstr = [NSString stringWithFormat:@" \"%@\"=\'%@\' and",_attributesArray[i],pLabel.text];
_deleateCondition = [_deleateCondition stringByAppendingString:pstr];
}
NSLog(@" %@",_deleateCondition);
//
[_manager deleateDataFromSheet:self.title where:_deleateCondition];
_deleateCondition = @"";
//,
_allDataArray = [_manager getSheetDataWithSheet:self.title];
if (![_searchCondition isEqual: @""]) {
NSLog(@"");
_allDataArray = [_manager searchDataFromSheet:self.title where:_searchCondition];
}
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(@"");
// _updateCondition = @"";
// LccDataCell *cell = [tableView cellForRowAtIndexPath:indexPath];
// NSMutableArray *array = [[NSMutableArray alloc]init];
// for (int i = 0; i < _attributesArray.count; i ++) {
// UILabel *pLabel = [cell viewWithTag:i+100];
// [array addObject:pLabel.text];
// if (i == _attributesArray.count - 1) {
// NSString *pstr = [NSString stringWithFormat:@" \"%@\"=\'%@\' ",_attributesArray[i],pLabel.text];
// _updateCondition = [_updateCondition stringByAppendingString:pstr];
// break;
// }
// NSString *pstr = [NSString stringWithFormat:@" \"%@\"=\'%@\' and",_attributesArray[i],pLabel.text];
// _updateCondition = [_updateCondition stringByAppendingString:pstr];
//
// }
//
// //
// _dataUpdateView = [[DataUpdateView alloc]initWithFrame:CGRectMake(0, -KHeight, KWidth, KHeight)];
// _dataUpdateView.delegate = self;
// _dataUpdateView.sheetTitle = self.title;
// _dataUpdateView.cellCount = _attributesArray.count;
// _dataUpdateView.updateContidion = _updateCondition;
// _dataUpdateView.dataArray = array;
//
// [self.navigationController.view addSubview:_dataUpdateView];
// [self.navigationController.view bringSubviewToFront:_dataUpdateView];
//
// NSLog(@"%@",_updateCondition);
// [UIView animateWithDuration:.3 animations:^{
// _dataUpdateView.frame = CGRectMake(0, 0, KWidth, KHeight);
// } completion:nil] ;
//
_dataUpdateView = [[DataUpdateView alloc] initWithFrame:CGRectMake(0, 0, KWidth, KHeight)];
_dataUpdateView.delegate = self;
_dataUpdateView.sheetTitle = self.sheetTitle;
_dataUpdateView.updateArray = _allDataArray[indexPath.row];
[self.navigationController.view addSubview:_dataUpdateView];
}
#pragma mark - InsertViewDelegate
- (void)closeInsertlView{
[_dataInsertView endEditing:YES];
[UIView animateWithDuration:.2 animations:^{
_dataInsertView.frame = CGRectMake(0, -KHeight, KWidth, KHeight);
} completion:nil];
}
-(void)insertSuccess{
//
[self _clearCondition];
_allDataArray = [_manager getSheetDataWithSheet:self.title];
[self.tableView reloadData];
UIAlertController *alter = [UIAlertController alertControllerWithTitle:@""
message:@""
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cannleAction = [UIAlertAction actionWithTitle:@"" style:UIAlertActionStyleDefault handler:nil];
[alter addAction:cannleAction];
[self presentViewController:alter animated:YES completion:nil];
}
-(void)insertError{
UIAlertController *alter = [UIAlertController alertControllerWithTitle:@""
message:@""
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cannleAction = [UIAlertAction actionWithTitle:@"" style:UIAlertActionStyleDefault handler:nil];
[alter addAction:cannleAction];
[self presentViewController:alter animated:YES completion:nil];
}
#pragma mark - DataUpdateViewDelegate
- (void)closeUpdateView{
[_dataUpdateView endEditing:YES];
NSLog(@"");
[UIView animateWithDuration:.2 animations:^{
_dataUpdateView.frame = CGRectMake(0, -KHeight, KWidth, KHeight);
} completion:nil];
}
-(void)updateSuccess{
_updateCondition = @"";
//,
_allDataArray = [_manager getSheetDataWithSheet:self.sheetTitle];
if (![_searchCondition isEqual: @""]) {
NSLog(@"");
_allDataArray = [_manager searchDataFromSheet:self.sheetTitle where:_searchCondition];
}
[self.tableView reloadData];
UIAlertController *alter = [UIAlertController alertControllerWithTitle:@""
message:@""
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cannleAction = [UIAlertAction actionWithTitle:@"" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[self closeUpdateView];
}];
[alter addAction:cannleAction];
[self presentViewController:alter animated:YES completion:nil];
}
-(void)updateError{
UIAlertController *alter = [UIAlertController alertControllerWithTitle:@""
message:@""
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cannleAction = [UIAlertAction actionWithTitle:@"" style:UIAlertActionStyleDefault handler:nil];
[alter addAction:cannleAction];
[self presentViewController:alter animated:YES completion:nil];
}
#pragma mark - DataAlterFieldViewDelegate
- (void)alterFieldSuccess {
_attributesArray = [_manager getSheetAttributesWithSheet:self.sheetTitle];
_allDataArray = [_manager getSheetDataWithSheet:self.sheetTitle];
[self.tableView reloadData];
[self tipView];
}
#pragma mark - private
- (void)setupNav {
LccButton * createButton = [LccButton buttonWithType:UIButtonTypeSystem];
[createButton setTitle:@"" forState:UIControlStateNormal];
[createButton addTarget:self action:@selector(rightBarClick) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *createButtonItem = [[UIBarButtonItem alloc]initWithCustomView:createButton];
[self.navigationItem setRightBarButtonItem: createButtonItem];
}
- (void)rightBarClick {
UIAlertController *alter = [UIAlertController alertControllerWithTitle:@""
message:@""
preferredStyle:UIAlertControllerStyleAlert];
[alter addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @"15";
[textField addTarget:self action:@selector(_inputChangeAction:) forControlEvents:UIControlEventEditingChanged];
}];
_nextAction = [UIAlertAction actionWithTitle:@"" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
// _sheetInsertView = [[SheetInsertView alloc]initWithFrame:CGRectMake(0, -KHeight, KWidth, KHeight) ];
// _sheetInsertView.cellCount = _attributesCount;
// _sheetInsertView.delegate = self;
// [self.navigationController.view addSubview:_sheetInsertView];
// [self.navigationController.view bringSubviewToFront:_sheetInsertView];
//
// [UIView animateWithDuration:.3 animations:^{
// _sheetInsertView.frame = CGRectMake(0, 0, KWidth, KHeight);
// } completion:nil];
_alterFieldView = [[DataAlterFieldView alloc] initWithFrame:CGRectMake(0, 0, KWidth, KHeight)];
_alterFieldView.sheetTitle = self.sheetTitle;
_alterFieldView.cellCount = _alterCount;
_alterFieldView.delegate = self;
[self.navigationController.view addSubview:_alterFieldView];
}];
_nextAction.enabled = NO;
UIAlertAction *cannleAction = [UIAlertAction actionWithTitle:@"" style:UIAlertActionStyleDefault handler:nil];
[alter addAction:_nextAction];
[alter addAction:cannleAction];
[self presentViewController:alter animated:YES completion:nil];
}
- (void)_inputChangeAction:(UITextField *)pTextFiled{
_nextAction.enabled = NO;
NSLog(@"%@",pTextFiled.text);
if ([pTextFiled.text integerValue] >= 1 && [pTextFiled.text integerValue] <=5) {
_nextAction.enabled = YES;
// _attributesCount = [pTextFiled.text integerValue];
_alterCount = [pTextFiled.text integerValue];
}
}
- (void)tipView {
UIAlertController *alter = [UIAlertController alertControllerWithTitle:@""
message:@""
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cannleAction = [UIAlertAction actionWithTitle:@"" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}];
[alter addAction:cannleAction];
[self presentViewController:alter animated:YES completion:nil];
}
#pragma mark - Action
- (void)_buttonAction:(UIButton *)pButton{
if (pButton.tag == 0) {
// NSLog(@"");
// [UIView animateWithDuration:.3 animations:^{
// _dataInsertView.frame = CGRectMake(0, 0, KWidth, KHeight);
// } completion:^(BOOL finished) {
// }];
//
_dataInsertView = [[DataInsertView alloc]initWithFrame:CGRectMake(0, 0 , KWidth, KHeight)];
_dataInsertView.delegate = self;
_dataInsertView.sheetTitle = self.title;
[self.navigationController.view addSubview:_dataInsertView];
[self.navigationController.view bringSubviewToFront:_dataInsertView];
}
if (pButton.tag == 1) {
pButton.selected = !pButton.selected;
[self.tableView setEditing:pButton.selected animated:YES];
}
if (pButton.tag == 2) {
NSLog(@"");
UIAlertController *alter = [UIAlertController alertControllerWithTitle:@""
message:@""
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cannleAction = [UIAlertAction actionWithTitle:@"" style:UIAlertActionStyleDefault handler:nil];
[alter addAction:cannleAction];
[self presentViewController:alter animated:YES completion:nil];
}
if (pButton.tag == 3) {
NSLog(@"");
UIAlertController *alter = [UIAlertController alertControllerWithTitle:@""
message:@",;:=LCCand>20 "
preferredStyle:UIAlertControllerStyleAlert];
[alter addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @":and,";
}];
UIAlertAction *searchAction = [UIAlertAction actionWithTitle:@"" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
_searchCondition = alter.textFields[0].text;
NSLog(@"_searchCondition = %@", _searchCondition);
if ([_searchCondition isEqual: @""]) {
_allDataArray = [_manager getSheetDataWithSheet:self.sheetTitle];
[self.tableView reloadData];
}
else{
_allDataArray = [_manager searchDataFromSheet:self.sheetTitle where:_searchCondition];
[self.tableView reloadData];
}
}];
UIAlertAction *cannleAction = [UIAlertAction actionWithTitle:@"" style:UIAlertActionStyleDefault handler:nil];
[alter addAction:cannleAction];
[alter addAction:searchAction];
_searchCondition = @"";
[self presentViewController:alter animated:YES completion:nil];
}
}
- (void)_clearCondition{
_searchCondition = @"";
_updateCondition = @"";
_deleateCondition = @"";
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/12 - DataPersistence(数据持久化)/W3C/LCCSqliteManager/UI/DataList/DataListController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 3,636 |
```objective-c
//
// InsertView.h
// DatabaseMangerDemo
//
// Created by LccLcc on 15/12/3.
//
#import <UIKit/UIKit.h>
@protocol InsertViewDelegate <NSObject>
//
- (void)insertError;
//
- (void)insertSuccess;
//
- (void)closeInsertlView;
@end
@interface DataInsertView : UIView //<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)NSString *sheetTitle;
@property(nonatomic,weak)id<InsertViewDelegate>delegate;
@property(nonatomic,strong)UITableView *tableView;
@end
``` | /content/code_sandbox/BigShow1949/Classes/12 - DataPersistence(数据持久化)/W3C/LCCSqliteManager/UI/DataList/DataInsertView.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 118 |
```objective-c
//
// DataListController.h
// DatabaseMangerDemo
//
// Created by LccLcc on 15/12/1.
//
#import <UIKit/UIKit.h>
@interface DataListController : UIViewController
//
@property(nonatomic,strong)NSString *sheetTitle;
//
@property(nonatomic,strong)NSArray *attributesArray;
//
@property(nonatomic,strong)UITableView *tableView;
@end
``` | /content/code_sandbox/BigShow1949/Classes/12 - DataPersistence(数据持久化)/W3C/LCCSqliteManager/UI/DataList/DataListController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 78 |
```objective-c
//
// DataEditView.m
// BigShow1949
//
// Created by zhht01 on 16/4/22.
//
#import "DataEditView.h"
#import "Define.h"
#import "LccCell.h"
#import "LCCSqliteManager.h"
@interface DataEditView ()
{
LCCSqliteManager *_manager;
}
@end
@implementation DataEditView
- (instancetype)initWithFrame:(CGRect)frame{
if (self = [super initWithFrame:frame]) {
//
UIView * blackgroundView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KWidth, KHeight)];
[self addSubview:blackgroundView];
blackgroundView.backgroundColor = [UIColor colorWithWhite:0 alpha:.5];
//
self.tableView = [[UITableView alloc]initWithFrame:CGRectMake((KWidth - 300)/2, 70, 300, KHeight - 250)];
if (iPhone4) {
self.tableView.frame = CGRectMake((KWidth - 300)/2, 40, 300, KHeight - 250);
}
[blackgroundView addSubview:self.tableView ];
self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
//
UIButton *ensureButton = [[UIButton alloc]initWithFrame:CGRectMake(10, 70, 40, 40)];
if (iPhone4) {
ensureButton.frame = CGRectMake(10, 30, 40, 40);
}
[blackgroundView addSubview:ensureButton];
[ensureButton setImage:[UIImage imageNamed:@"btn_save"] forState:UIControlStateNormal];
[ensureButton addTarget:self action:@selector(_insertAction) forControlEvents:UIControlEventTouchUpInside];
//
UIButton *deleateButton = [[UIButton alloc]initWithFrame:CGRectMake(KWidth - 50, 70, 40, 40)];
if (iPhone4) {
deleateButton.frame = CGRectMake(KWidth - 50, 30, 40, 40);
}
[blackgroundView addSubview:deleateButton];
[deleateButton setImage:[UIImage imageNamed:@"btn_cannel"] forState:UIControlStateNormal];
[deleateButton addTarget:self action:@selector(_deleateAction) forControlEvents:UIControlEventTouchUpInside];
_manager = [LCCSqliteManager shareInstance];
}
return self;
}
#pragma mark - private
- (void)_insertAction {
// cell
NSMutableArray *dataArray = [NSMutableArray array];
for (int i = 0; i < self.placeholders.count; i ++) { // texts
NSIndexPath *path = [NSIndexPath indexPathForRow:i inSection:0];
LccCell *pCell = [self.tableView cellForRowAtIndexPath:path ];
if (pCell.textFiled.text) { // text nil
[dataArray addObject:pCell.textFiled.text];
}else {
[dataArray addObject:@""];
}
}
// cell
if (!self.texts.count) { // ,
for (int i = 0; i < self.placeholders.count; i ++) { //
NSIndexPath *path = [NSIndexPath indexPathForRow:i inSection:0];
LccCell *pCell = [self.tableView cellForRowAtIndexPath:path ];
NSLog(@"pcell = %@",pCell);
if (pCell != nil && [pCell.textFiled.text isEqualToString:@""]) {
// [self.delegate insertError];
return;
}
}
}
if ([self.delegate respondsToSelector:@selector(ensureAction:)]) {
[self.delegate ensureAction:(NSArray *)dataArray];
}
}
- (void)_deleateAction {
if ([self.delegate respondsToSelector:@selector(closeAction)]) {
[self.delegate closeAction];
}
}
#pragma mark - TableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.placeholders.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
LccCell *cell = [tableView dequeueReusableCellWithIdentifier:@"inputCell"];
if (cell == nil) {
cell = [[LccCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"inputCell" andWidth:300];
}
cell.tag = indexPath.row;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
//
cell.textFiled.placeholder = self.placeholders[indexPath.row];
cell.textFiled.text = self.texts[indexPath.row];
cell.backgroundColor = [UIColor clearColor];
return cell;
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/12 - DataPersistence(数据持久化)/W3C/LCCSqliteManager/UI/DataList/DataEditView.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 938 |
```objective-c
//
// InsertView.m
// DatabaseMangerDemo
//
// Created by LccLcc on 15/12/3.
//
#import "Define.h"
#import "DataInsertView.h"
#import "LccCell.h"
#import "LCCSqliteManager.h"
#import "DataEditView.h"
@interface DataInsertView ()<DataEditViewDelegate>
@end
@implementation DataInsertView
{
LCCSqliteManager *_manager;
DataEditView *_dataEditView;
}
- (instancetype)initWithFrame:(CGRect)frame{
if (self = [super initWithFrame:frame]) {
//
_dataEditView = [[DataEditView alloc] initWithFrame:frame];
_dataEditView.delegate = self;
[self addSubview:_dataEditView];
}
return self;
}
- (void)setSheetTitle:(NSString *)sheetTitle {
_sheetTitle = sheetTitle;
NSArray *attribute = [[LCCSqliteManager shareInstance] getSheetAttributesWithSheet:sheetTitle];
_dataEditView.placeholders = attribute;
[_dataEditView.tableView reloadData];
}
#pragma mark -Action
//
- (void)ensureAction:(NSArray *)dataArray {
NSLog(@" %@",dataArray);
LCCSqliteManager *manger = [LCCSqliteManager shareInstance];
BOOL result = [manger insertDataToSheet :self.sheetTitle withData:dataArray];
if (result == YES) {
[self.delegate insertSuccess];
}
if (result == NO) {
[self.delegate insertError];
}
}
//
- (void)closeAction {
[self removeFromSuperview];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/12 - DataPersistence(数据持久化)/W3C/LCCSqliteManager/UI/DataList/DataInsertView.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 350 |
```objective-c
//
// Define.h
//
//
// Created by LccLcc on 15/9/7.
//
#import <Foundation/Foundation.h>
#define KHeight [UIScreen mainScreen].bounds.size.height
#define KWidth [UIScreen mainScreen].bounds.size.width
#define iPhone4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640,960),[[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640,1136),[[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750,1334),[[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone6P ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242,2208),[[UIScreen mainScreen] currentMode].size) : NO)
@interface Define : NSObject
@end
``` | /content/code_sandbox/BigShow1949/Classes/12 - DataPersistence(数据持久化)/W3C/LCCSqliteManager/Tools/Define.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 217 |
```objective-c
//
// LccDataCell.h
// DatabaseMangerDemo
//
// Created by LccLcc on 15/12/2.
//
#import <UIKit/UIKit.h>
@interface LccDataCell : UITableViewCell
//
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier data:(NSArray * )pArray;
@end
``` | /content/code_sandbox/BigShow1949/Classes/12 - DataPersistence(数据持久化)/W3C/LCCSqliteManager/UI/DataList/LccDataCell.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 76 |
```objective-c
//
// LCCSqliteGCD.h
// LCCSqliteManagerDemo
//
// Created by LccLcc on 15/12/19.
//
#import <Foundation/Foundation.h>
@interface LCCSqliteGCD : NSObject
@end
``` | /content/code_sandbox/BigShow1949/Classes/12 - DataPersistence(数据持久化)/W3C/LCCSqliteManager/Tools/LCCSqliteManager/LCCSqliteGCD.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 57 |
```objective-c
//
// LCCSqliteSheetHandler.h
// LCCSqliteManagerDemo
//
// Created by LccLcc on 15/12/24.
//
#import <Foundation/Foundation.h>
typedef NS_ENUM(NSInteger, LCCSheetReferencesType) {
/*
. cascade
update/deleteupdate/delete
. No action
,update/delete
. Set default
, Innodb
*/
LCCSqliteReferencesKeyTypeDefault = 0, //, Innodb
LCCSqliteReferencesKeyTypeCasCade = 1, //update/delete,update/delete
LCCSqliteReferencesKeyTypeNoAction = 2, //,update/delete
};
typedef NS_ENUM(NSInteger, LCCSheetType) {
LCCSheetTypeTemperory = 0,//
LCCSheetTypeVariable = 1,//
};
@interface LCCSqliteSheetHandler : NSObject
//
@property(nonatomic,assign)LCCSheetType sheetType;
//
@property(nonatomic,strong)NSString *sheetName;
//
@property(nonatomic,strong)NSArray *sheetField;
//
@property(nonatomic,strong)NSArray *primaryKey;
//
@property(nonatomic,strong)NSArray *forgienKey;
//
@property(nonatomic,strong)NSString *referencesSheetName;
//
@property(nonatomic,strong)NSArray *referenceskey;
//()
@property(nonatomic,assign)LCCSheetReferencesType deleateReferencesType;
//()
@property(nonatomic,assign)LCCSheetReferencesType updateReferencesType;
//sql
@property(nonatomic,strong)NSString *targetSql;
- (NSString *)returnTargetSql;
@end
``` | /content/code_sandbox/BigShow1949/Classes/12 - DataPersistence(数据持久化)/W3C/LCCSqliteManager/Tools/LCCSqliteManager/LCCSqliteSheetHandler.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 322 |
```objective-c
//
// LCCSqliteGCD.m
// LCCSqliteManagerDemo
//
// Created by LccLcc on 15/12/19.
//
#import "LCCSqliteGCD.h"
@implementation LCCSqliteGCD
@end
``` | /content/code_sandbox/BigShow1949/Classes/12 - DataPersistence(数据持久化)/W3C/LCCSqliteManager/Tools/LCCSqliteManager/LCCSqliteGCD.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 59 |
```objective-c
//
// LCCSqliteSheetHandler.m
// LCCSqliteManagerDemo
//
// Created by LccLcc on 15/12/24.
//
#import "LCCSqliteSheetHandler.h"
@implementation LCCSqliteSheetHandler
{
NSString * _deleateTypeStr;
NSString * _updateTypeStr;
}
- (instancetype)init{
if (self = [super init]) {
_targetSql = [[NSString alloc]init];
//
_sheetType = LCCSheetTypeVariable;
_deleateReferencesType = LCCSqliteReferencesKeyTypeCasCade;
_updateReferencesType = LCCSqliteReferencesKeyTypeCasCade;
}
return self;
}
- (NSString *)returnTargetSql{
//
if (!_sheetName || !_sheetField) {
NSLog(@"sql:");
return nil;
}
//
NSMutableArray *attributes = [[NSMutableArray alloc]init];
//
if (_sheetField) {
for (int i = 0; i < _sheetField.count; i++) {
NSString * att = [NSString stringWithFormat:@"\"%@\" TEXT",_sheetField[i]];
[attributes addObject:att];
}
}
//
if (_primaryKey) {
NSString* primaryKeyString = [[NSString alloc]init];
for (int i = 0; i < _primaryKey.count; i++) {
if (i==_primaryKey.count - 1) {
primaryKeyString = [primaryKeyString stringByAppendingString:[NSString stringWithFormat:@" \"%@\" ",_primaryKey[i]]];
break;
}
primaryKeyString = [primaryKeyString stringByAppendingString:[NSString stringWithFormat:@" \"%@\", ",_primaryKey[i]]];
}
[attributes addObject:[NSString stringWithFormat:@"PRIMARY KEY (%@)",primaryKeyString]];
}
//
if ( _forgienKey&&_referenceskey&&_referencesSheetName) {
if (_forgienKey.count != _referenceskey.count) {
NSLog( @"sql:");
return nil;
}
NSString * forengiKeyString = [[NSString alloc]init];
NSString * referencesKeyString = [[NSString alloc]init];
for (int i = 0; i < _forgienKey.count; i++) {
if (i==_forgienKey.count - 1) {
forengiKeyString = [forengiKeyString stringByAppendingString:[NSString stringWithFormat:@" \"%@\" ",_forgienKey[i]]];
referencesKeyString = [referencesKeyString stringByAppendingString:[NSString stringWithFormat:@" \"%@\" ",_referenceskey[i]]];
break;
}
forengiKeyString = [forengiKeyString stringByAppendingString:[NSString stringWithFormat:@" \"%@\", ",_forgienKey[i]]];
referencesKeyString = [referencesKeyString stringByAppendingString:[NSString stringWithFormat:@" \"%@\", ",_referenceskey[i]]];
}
[self _referenceTypeJudge];
[attributes addObject:[NSString stringWithFormat:@"FOREIGN KEY (%@) REFERENCES \"%@\" (%@) ON UPDATE %@ ON DELETE %@",forengiKeyString,_referencesSheetName,referencesKeyString,_updateTypeStr,_deleateTypeStr]];
}
NSString *_conditionString = [[NSString alloc]init];
for (int i = 0 ; i < attributes.count; i ++) {
if (i == attributes.count - 1) {
_conditionString = [_conditionString stringByAppendingString:[NSString stringWithFormat:@"%@\n",attributes[i]]];
break;
}
_conditionString = [_conditionString stringByAppendingString:[NSString stringWithFormat:@"%@,\n",attributes[i]]];
}
if (_sheetType == LCCSheetTypeTemperory) {
_targetSql = [NSString stringWithFormat:@" CREATE TEMP TABLE \"%@\" (\n%@) ",_sheetName,_conditionString];
}
if (_sheetType == LCCSheetTypeVariable) {
_targetSql = [NSString stringWithFormat:@" CREATE TABLE \"%@\" (\n%@) ",_sheetName,_conditionString];
}
NSLog(@"sql:\n %@",_targetSql);
return _targetSql;
}
- (void)_referenceTypeJudge{
switch (_deleateReferencesType) {
case LCCSqliteReferencesKeyTypeCasCade:
_deleateTypeStr = @"CASCADE";
break;
case LCCSqliteReferencesKeyTypeDefault:
_deleateTypeStr = @"SET DEFAULT";
break;
case LCCSqliteReferencesKeyTypeNoAction:
_deleateTypeStr = @"NO ACTION";
break;
default:
break;
}
switch (_updateReferencesType) {
case LCCSqliteReferencesKeyTypeCasCade:
_updateTypeStr = @"CASCADE";
break;
case LCCSqliteReferencesKeyTypeDefault:
_updateTypeStr = @"SET DEFAULT";
break;
case LCCSqliteReferencesKeyTypeNoAction:
_updateTypeStr = @"NO ACTION";
break;
default:
break;
}
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/12 - DataPersistence(数据持久化)/W3C/LCCSqliteManager/Tools/LCCSqliteManager/LCCSqliteSheetHandler.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 1,048 |
```objective-c
//
// LCCSqliteManager.h
// LCCSqliteManagerDemo
//
// Created by LccLcc on 15/11/25.
//
#import <Foundation/Foundation.h>
#import "LCCSqliteSheetHandler.h"
#import <sqlite3.h>
@interface LCCSqliteManager : NSObject
/**
* # manager
*/
+ (LCCSqliteManager*)shareInstance;
#pragma mark - Sqlite
/**
* #
*/
+ (NSString*)sqliteLibVersion;
/**
* #
*/
+ (BOOL)isSqliteThreadSafe;
#pragma mark - manager
/**
* # ,
* @ ios,
*/
- (BOOL)openSqliteFile:(NSString *)filename;
/**
* #
* @ :OCOC
*/
- (BOOL)closeSqliteFile;
/**
* #
* @
*/
- (BOOL)deleateSqliteFile:(NSString *)filename;
#pragma mark - manager
/**
* #
*/
- (NSArray*)getAllSheetNames;
/**
* #
* @ pAttributes,pAttributes,
* @ pName = @,pAttributes = @[@"",@,@""];
* @ @nil@,
* @ primaryKey
* @ 1.1
*/
//- (BOOL)createSheetWithName:(NSString *)pName attributes:(NSArray *)pAttributes primaryKey:(NSString *)pkey;
/**
* #
* @ ():
* @ ,,
* @
* @1.1
*/
//- (BOOL)createSheetWithName:(NSString *)pName attributes:(NSArray *)pAttributes primaryKey:(NSString *)pKey referenceSheet:(NSString*)oldName referenceType:(LCCSheetReferencesType)type;
/**
* #
* @ 1.1blocksheetLCCSqliteSheetHandler
*/
- (BOOL)createSheetWithSheetHandler:(void (^)(LCCSqliteSheetHandler *sheet)) sheetHandler;
/**
* #
* @
*/
- (BOOL)deleateSheetWithName:(NSString *)pName;
/**
* #
* @,
*/
- (NSArray *)getSheetAttributesWithSheet:(NSString *)pName;
/**
* #
* @ ,NSInteger
*/
- (NSInteger )getSheetAttributesCountWithSheet:(NSString *)pName;
/**
* #
* @ ,NSArray
* @
*/
- (NSArray *)getSheetPrimaryKeyWithSheet:(NSString *)pName;
/**
* #
* @ ,,,
*/
- (NSArray *)getSheetDataWithSheet:(NSString *)pName;
/**
* #
* @ ,NSInteger
*/
- (NSInteger )getSheetDataCountWithSheet:(NSString *)pName;
/**
* #
* @
*/
- (void)copySheetWithSheet:(NSString *)sheetName;
/**
* #
* @attribute
*/
- (BOOL)addColumnToSheet:(NSString *)sheetName withAttribute:(NSString *)attribute;
/**
* #
* @attributeArray ,
*/
- (BOOL)addColumnToSheet:(NSString *)sheetName withAttributeArray:(NSArray *)attributeArray;
/**
* #
* @
*/
- (void)changeColumnToSheet:(NSString *)sheetName newAttribute:(NSString *)newAttribute oldAttribute:(NSString *)oldAttribute;
/**
* #
* @
*/
- (void)createIndexToSheet:(NSString *)sheetName withIndex:(NSArray *)index;
/**
* #
* @
*/
- (void)searchWithSheets:(NSArray *)sheetS where:(NSString *)condition;
#pragma mark -manager
/**
* # ,
* @ ,,,,
[_manager insertDataToSheet:@"" withData @[@LCC,@16,@"100"]],,count
,No
*/
- (BOOL)insertDataToSheet:(NSString *)sheetName withData:(NSArray *)data;
/**
* #
* @ ,,=LCC:
[_manager searchDataFromSheet:@ Where:@" \\"=\'LCC\' " condition() \='LCC'1='',1""
* @ TEXT
* @:
* @:NSString *priciseContion = [NSString stringWithFormat:@" \"\"=\'LCC\' "];
* @:NSString *fuzzyContion = [NSString stringWithFormat:@" \"\"Like\'%\' "];
* @:NSString *compareContion = [NSString stringWithFormat:@" \"\">\'100\' "];
* @....others
* @and>80:
NSString * searchCondition = @" \"\" Like \'%\' and \"\" > \'80\' ";
[_manager searchDataFromSheet:@"" where:searchCondition ]
* @ TEXT'20' '3'NSInteger'20' '03'
*/
- (NSArray *)searchDataFromSheet:(NSString *)sheetName where:(NSString *)condition;
/**
* #
* @ ,
* @ =LCC[_manager deleateDataWhiere:@" \""= \'LCC\' " from:@""];
* @ tableViewtableViewcelltableView
* @ rowidtableViewCellindexPathrowidcell
*/
- (BOOL)deleateDataFromSheet:(NSString *)sheetName where:(NSString *)condition;
/**
* #
* @
* @ =LCC[_manager updateDataToSheet:@"" withData:@[@"Lcc",@"16",@"100"] Where:@" \""= \'LCC\' "];
* @
*/
- (BOOL)updateDataToSheet:(NSString *)sheetName withData:(NSArray *)data where:(NSString *)condition;
#pragma mark - ForeignKey
/**
* #
* @
*/
- (BOOL)closeForeignkey;
@end
``` | /content/code_sandbox/BigShow1949/Classes/12 - DataPersistence(数据持久化)/W3C/LCCSqliteManager/Tools/LCCSqliteManager/LCCSqliteManager.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 1,136 |
```objective-c
//
// FMDBBaseUseViewController.h
// BigShow1949
//
// Created by zhht01 on 16/4/15.
//
#import <UIKit/UIKit.h>
/*
: path_to_url
*/
@interface FMDBBaseUseViewController : UIViewController
- (IBAction)insert:(id)sender;
- (IBAction)delete_:(id)sender;
- (IBAction)update:(id)sender;
- (IBAction)select:(id)sender;
@end
``` | /content/code_sandbox/BigShow1949/Classes/12 - DataPersistence(数据持久化)/FMDB基本使用/FMDBBaseUseViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 96 |
```objective-c
//
// FMDBBaseUseViewController.m
// BigShow1949
//
// Created by zhht01 on 16/4/15.
//
#import "FMDBBaseUseViewController.h"
#import "FMDB.h"
@interface FMDBBaseUseViewController ()
@property (nonatomic, strong) FMDatabase *db;
@end
@implementation FMDBBaseUseViewController
-(void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
//1.
NSString *doc = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *fileName=[doc stringByAppendingPathComponent:@"student.sqlite"];
NSLog(@"fileName = %@", fileName);
//2.
FMDatabase *db = [FMDatabase databaseWithPath:fileName];
//3.
if ([db open]) {
// 4.
BOOL result = [db executeUpdate:@"CREATE TABLE IF NOT EXISTS t_student (id integer PRIMARY KEY AUTOINCREMENT, name text NOT NULL, age integer NOT NULL);"];
if (result) {
NSLog(@"");
}else
{
NSLog(@"");
}
}
self.db = db;
}
//
- (void)crate {
[self.db executeUpdate:@"CREATE TABLE IF NOT EXISTS t_student (id integer PRIMARY KEY AUTOINCREMENT, name text NOT NULL, age integer NOT NULL);"];
}
- (IBAction)insert:(id)sender {
for (int i = 0; i<10; i++) {
NSString *name = [NSString stringWithFormat:@"jack-%d", arc4random_uniform(100)];
// executeUpdate : ?
BOOL result = [self.db executeUpdate:@"INSERT INTO t_student (name, age) VALUES (?, ?);", name, @(arc4random_uniform(40))];
if (result) {
NSLog(@"");
}else {
NSLog(@"error");
}
// [self.db executeUpdate:@"INSERT INTO t_student (name, age) VALUES (?, ?);" withArgumentsInArray:@[name, @(arc4random_uniform(40))]];
// executeUpdateWithFormat : %@%d
// [self.db executeUpdateWithFormat:@"INSERT INTO t_student (name, age) VALUES (%@, %d);", name, arc4random_uniform(40)];
}
}
- (IBAction)delete_:(id)sender {
// [self.db executeUpdate:@"DELETE FROM t_student;"];
[self.db executeUpdate:@"DROP TABLE IF EXISTS t_student;"];
}
- (IBAction)update:(id)sender {
// :t_studentnamejack-101age40
[self.db executeUpdate:@"UPDATE t_student SET name = 'jack-101', age = 40 WHERE id = 4"];
// //
// [self.db executeUpdate:@"UPDATE t_student SET AGE"];
}
- (IBAction)select:(id)sender {
// 1.
FMResultSet *resultSet = [self.db executeQuery:@"SELECT * FROM t_student"];
// 2.
while ([resultSet next]) {
int ID = [resultSet intForColumn:@"id"];
NSString *name = [resultSet stringForColumn:@"name"];
int age = [resultSet intForColumn:@"age"];
NSLog(@"%d %@ %d", ID, name, age);
}
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/12 - DataPersistence(数据持久化)/FMDB基本使用/FMDBBaseUseViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 708 |
```objective-c
//
// YFLabelViewController.m
// BigShow1949
//
// Created by zhht01 on 16/3/22.
//
#import "YFLabelViewController.h"
@interface YFLabelViewController ()
@end
@implementation YFLabelViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setupDataArr:@[@[@"",@"YFAutolayoutTagViewController_UIStoryboard"],
@[@"",@"YFSphereTagCloud"],
@[@"2",@"YFSphereViewController"],
@[@"",@"YFTagsCloudViewController_UIStoryboard"],
@[@"",@"YFShineLabelViewController"],
@[@"2",@"YFLazyInViewController_UIStoryboard"],
@[@"",@"YFDynamicLabelViewController"],
@[@"",@"YFMarqueeViewController"],
@[@"",@"YFPrinterEffectViewController"],
@[@"",@"YFRatingBarViewController"]]];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/YFLabelViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 187 |
```objective-c
//
// LCCSqliteManager.m
// LCCSqliteManagerDemo
//
// Created by LccLcc on 15/11/25.
//
#import "LCCSqliteManager.h"
@implementation LCCSqliteManager
{
sqlite3 *_sqlite ;
}
+ (LCCSqliteManager *)shareInstance{
static LCCSqliteManager *instance = nil;
static dispatch_once_t token;
dispatch_once(&token, ^{
instance = [[[self class ]alloc ]init];
});
return instance;
}
#pragma mark -
+ (NSString*)sqliteLibVersion {
return [NSString stringWithFormat:@"%s", sqlite3_libversion()];
}
+ (BOOL)isSqliteThreadSafe {
return sqlite3_threadsafe() != 0;
}
#pragma mark -
- (BOOL)openSqliteFile:(NSString *)filename{
if (_sqlite) {
NSLog(@"error:");
return YES;
}
if (!filename) {
NSLog(@"error:");
return NO;
}
NSString *filePath = [NSHomeDirectory() stringByAppendingFormat: @"/Documents/%@.sqlite", filename];
int result = sqlite3_open([filePath UTF8String], &_sqlite);
if (result != SQLITE_OK) {
NSLog(@"error:%@",filename);
return NO;
}
NSLog(@"%@,:%@",filename,filePath);
[self openForeignkey];
return YES;
}
- (BOOL)closeSqliteFile{
if (!_sqlite) {
return YES;
}
int result;
BOOL retry;
BOOL triedFinalizingOpenStatements = NO;
do {
retry = NO;
result = sqlite3_close(_sqlite);
if (SQLITE_BUSY == result || SQLITE_LOCKED == result) {
if (!triedFinalizingOpenStatements) {
triedFinalizingOpenStatements = YES;
sqlite3_stmt *pStmt;
while ((pStmt = sqlite3_next_stmt(_sqlite, nil)) !=0) {
NSLog(@"Closing leaked statement");
sqlite3_finalize(pStmt);
retry = YES;
}
}
}
else if (result != SQLITE_OK ) {
NSLog(@"error closing!: %d", result);
}
}
while (retry);
_sqlite = nil;
return YES;
}
- (BOOL)deleateSqliteFile:(NSString *)filename{
[self closeSqliteFile];
NSFileManager * fileManager = [[NSFileManager alloc]init];
NSString *filePath = [NSHomeDirectory() stringByAppendingFormat: @"/Documents/%@.sqlite", filename];
NSError *error = nil;
[fileManager removeItemAtPath:filePath error:&error];
if (error) {
NSLog(@":%@",error);
return NO;
}
NSLog(@"%@",filename);
return YES;
}
#pragma mark -
- (NSArray *)getAllSheetNames{
if (!_sqlite) {
NSLog(@"error:");
return nil;
}
NSMutableArray *allSheetTitles = [[NSMutableArray alloc]init];
sqlite3_stmt *statement;
const char *getTableInfo = "SELECT * FROM sqlite_master WHERE type='table' ORDER by name";
int result = sqlite3_prepare_v2(_sqlite, getTableInfo, -1, &statement, nil);
if (result != SQLITE_OK) {
NSLog(@"error:");
return nil;
}
while (sqlite3_step(statement) == SQLITE_ROW) {
char *nameData = (char *)sqlite3_column_text(statement, 1);
NSString *tableName = [[NSString alloc] initWithUTF8String:nameData];
[allSheetTitles addObject:tableName];
}
return allSheetTitles;
}
- (BOOL)createSheetWithName:(NSString *)pName attributes:(NSArray *)pAttributes primaryKey:(NSString *)pkey{
if (!pName || !pAttributes) {
NSLog(@"error:");
return NO;
}
if (pAttributes.count == 0) {
NSLog(@"error:0");
return NO;
}
//
NSMutableArray *attributes = [[NSMutableArray alloc]init];
for (int i = 0; i < pAttributes.count; i++) {
NSString * att = [NSString stringWithFormat:@"\"%@\" TEXT",pAttributes[i]];
[attributes addObject:att];
}
if (pkey) {
[attributes addObject:[NSString stringWithFormat:@"PRIMARY KEY (\"%@\")",pkey]];
}
//SQL
NSString *appendString = [[NSString alloc]init];
for (int i = 0 ; i < attributes.count; i ++) {
if (i == attributes.count - 1) {
appendString = [appendString stringByAppendingString:attributes[i]];
break;
}
appendString = [appendString stringByAppendingString:[NSString stringWithFormat:@"%@,",attributes[i]]];
}
NSString *targetSql = [NSString stringWithFormat:@"CREATE TABLE \"%@\"(%@)",pName,appendString];
NSLog(@"sql = %@",targetSql);
//SQL
char *error = NULL;
int result = sqlite3_exec(_sqlite, [targetSql UTF8String], NULL, NULL, &error);
if (result != SQLITE_OK) {
NSLog(@":%s", error);
return NO;
}
NSLog(@"");
return YES;
}
- (BOOL)createSheetWithName:(NSString *)pName attributes:(NSArray *)pAttributes primaryKey:(NSString *)pKey referenceSheet:(NSString *)oldName referenceType:(LCCSheetReferencesType)type{
//
if (!pName || !pAttributes) {
NSLog(@"error:");
return NO;
}
if (pAttributes.count == 0) {
NSLog(@"error:0");
return NO;
}
//,
NSArray *oldSheetPK = [self getSheetPrimaryKeyWithSheet:oldName];
NSLog(@"%@",oldSheetPK);
if (!oldSheetPK) {
NSLog(@"error:");
return NO;
}
//
NSMutableArray *attributes = [[NSMutableArray alloc]init];
NSString *typeStr = @"CASCADE";
for (int i = 0; i < pAttributes.count; i++) {
NSString * att = [NSString stringWithFormat:@"\"%@\" TEXT",pAttributes[i]];
if ( [pKey isEqualToString: pAttributes[i]] ) {
att = [NSString stringWithFormat:@"\"%@\" TEXT PRIMARY KEY REFERENCES \"%@\" (\"%@\") ON DELETE %@",pAttributes[i],oldName,oldSheetPK,typeStr];
}
[attributes addObject:att];
}
//SQL
NSString *appendString = [[NSString alloc]init];
for (int i = 0 ; i < pAttributes.count; i ++) {
if (i == pAttributes.count - 1) {
appendString = [appendString stringByAppendingString:attributes[i]];
break;
}
appendString = [appendString stringByAppendingString:[NSString stringWithFormat:@"%@,",attributes[i]]];
}
NSString *targetSql = [NSString stringWithFormat:@"CREATE TABLE \"%@\"(%@)",pName,appendString];
NSLog(@"sql = %@",targetSql);
//SQL
char *error = NULL;
int result = sqlite3_exec(_sqlite, [targetSql UTF8String], NULL, NULL, &error);
if (result != SQLITE_OK) {
NSLog(@":%s", error);
return NO;
}
NSLog(@"");
return YES;
}
- (BOOL)createSheetWithSheetHandler:(void (^)(LCCSqliteSheetHandler *))sheetHandler{
LCCSqliteSheetHandler *sheet = [[LCCSqliteSheetHandler alloc]init];
sheetHandler(sheet);
NSString *targetSql = [sheet returnTargetSql];
if (!targetSql) {
return NO;
}
//SQL
char *error = NULL;
int result = sqlite3_exec(_sqlite, [targetSql UTF8String], NULL, NULL, &error);
if (result != SQLITE_OK) {
NSLog(@":%s", error);
return NO;
}
NSLog(@"");
return YES;
}
- (BOOL)deleateSheetWithName:(NSString *)pName{
if (!pName) {
NSLog(@"error:nil");
return NO;
}
//sql
NSString *targetSql = [NSString stringWithFormat:@"DROP TABLE \"%@\"",pName];
//SQL
char *error = NULL;
int result = sqlite3_exec(_sqlite, [targetSql UTF8String], NULL, NULL, &error);
if (result != SQLITE_OK) {
NSLog(@":%s", error);
return NO;
}
NSLog(@"");
return YES;
}
- (NSArray *)getSheetAttributesWithSheet:(NSString *)pName{
if (!pName) {
NSLog(@"error:nil");
return nil;
}
NSMutableArray *array = [[NSMutableArray alloc]init];
sqlite3_stmt *ppStmt;
NSString *targetSql = [NSString stringWithFormat:@"PRAGMA table_info(\"%@\")",pName];
const char *getTableInfo = [targetSql UTF8String];
//
sqlite3_prepare_v2(_sqlite, getTableInfo, -1, &ppStmt, nil);
while (sqlite3_step(ppStmt) == SQLITE_ROW) {
//,,
char *nameData = (char *)sqlite3_column_text(ppStmt, 1);
NSString *attributeName = [[NSString alloc] initWithUTF8String:nameData];
[array addObject:attributeName];
}
NSLog(@"");
return array;
}
- (NSInteger )getSheetAttributesCountWithSheet:(NSString *)pName{
NSInteger count = [self getSheetAttributesWithSheet:pName].count;
return count;
}
- (NSArray *)getSheetPrimaryKeyWithSheet:(NSString *)pName{
if (!pName) {
NSLog(@"error:nil");
return nil;
}
sqlite3_stmt *ppStmt;
NSString *targetSql = [NSString stringWithFormat:@"PRAGMA table_info(\"%@\")",pName];
const char *getTableInfo = [targetSql UTF8String];
//
NSMutableArray *primaryKey = [NSMutableArray array];
sqlite3_prepare_v2(_sqlite, getTableInfo, -1, &ppStmt, nil);
while (sqlite3_step(ppStmt) == SQLITE_ROW) {
char *nameData = (char *)sqlite3_column_text(ppStmt, 1);
char *isPrimaryKey = (char *)sqlite3_column_text(ppStmt, 5);
NSString *attributeName = [[NSString alloc] initWithUTF8String:nameData];
NSString *isPK = [[NSString alloc] initWithUTF8String:isPrimaryKey];
if ( ![isPK isEqualToString:@"0"]) {
[primaryKey addObject:attributeName];
}
}
NSLog(@" = %@",primaryKey);
return primaryKey;
}
- (NSArray *)getSheetDataWithSheet:(NSString *)pName{
NSMutableArray *dataArray = [NSMutableArray array];
NSInteger count = [self getSheetAttributesWithSheet:pName].count;
NSLog(@"%ld",(long)count);
//sql
NSString *targetsql = [NSString stringWithFormat:@"SELECT * FROM \"%@\" ",pName] ;
sqlite3_stmt *ppStmt = NULL;
int result = sqlite3_prepare_v2(_sqlite, [targetsql UTF8String], -1, &ppStmt, NULL);
if (result != SQLITE_OK) {
NSLog(@"");
return nil;
}
//
int hasData = sqlite3_step(ppStmt);
//
while (hasData == SQLITE_ROW) {
const unsigned char *str;
NSMutableArray *dataModel = [NSMutableArray array];
for (int i = 0 ; i < count; i++) {
str = sqlite3_column_text(ppStmt, i); //
if (str == NULL) {
[dataModel addObject:@""];
}
else{
[dataModel addObject:[NSString stringWithUTF8String:(const char*)str]];
}
}
//
[dataArray addObject:dataModel];
//
hasData = sqlite3_step(ppStmt);
}
NSLog(@", = %@",dataArray);
//
sqlite3_finalize(ppStmt);
return dataArray;
}
- (NSInteger )getSheetDataCountWithSheet:(NSString *)pName{
NSInteger count = [self getSheetDataWithSheet:pName].count;
return count;
}
- (void)copySheetWithSheet:(NSString *)sheetName{
}
- (BOOL)addColumnToSheet:(NSString *)sheetName withAttribute:(NSString *)attribute{
if (!sheetName) {
NSLog(@"error:nil");
return NO;
}
//sql // ALTER TABLE t_parking ADD cost date
NSString *targetSql = [NSString stringWithFormat:@"ALTER TABLE %@ ADD %@ TEXT DEFAULT ''", sheetName, attribute];
//SQL
char *error = NULL;
int result = sqlite3_exec(_sqlite, [targetSql UTF8String], NULL, NULL, &error);
if (result != SQLITE_OK) {
NSLog(@":%s", error);
return NO;
}
NSLog(@"");
return YES;
}
- (BOOL)addColumnToSheet:(NSString *)sheetName withAttributeArray:(NSArray *)attributeArray { //
if (!sheetName) {
NSLog(@"error:nil");
return NO;
}
if (!attributeArray.count) {
NSLog(@"");
return NO;
}
BOOL result = YES;
for (NSString *attribute in attributeArray) {
BOOL result2 = [self addColumnToSheet:sheetName withAttribute:attribute];
if (!result2) { //
result = NO;
}
}
return result;
}
- (void)changeColumnToSheet:(NSString *)sheetName newAttribute:(NSString *)newAttribute oldAttribute:(NSString *)oldAttribute{
}
- (void)searchWithSheets:(NSArray *)sheetS where:(NSString *)condition{
}
#pragma - mark
- (BOOL)insertDataToSheet:(NSString *)sheetName withData:(NSArray *)data {
//
NSInteger count = [self getSheetAttributesCountWithSheet:sheetName];
if (data.count != count) {
NSLog(@"error:");
return NO;
}
//sql,
NSString *placeHoderString = [[NSString alloc]init];
for (int i = 0 ; i < data.count; i ++) {
if (i == data.count - 1) {
placeHoderString = [placeHoderString stringByAppendingString:[NSString stringWithFormat:@" \"%@\" ",data[i]]];
break;
}
placeHoderString = [placeHoderString stringByAppendingString:[NSString stringWithFormat:@" \"%@\",",data[i]]];
}
NSString *targetString = [NSString stringWithFormat:@"INSERT INTO \"%@\" VALUES(%@)",sheetName,placeHoderString];
NSLog(@"%@",targetString);
//SQL
char *error = NULL;
int result = sqlite3_exec(_sqlite, [targetString UTF8String], NULL, NULL, &error);
if (result != SQLITE_OK) {
NSLog(@"error:%s",error);
return NO;
}
NSLog(@"");
return YES;
}
- (NSArray *)searchDataFromSheet:(NSString *)sheetName where:(NSString *)condition{
if (!sheetName || !condition) {
NSLog(@"error:");
return nil;
}
NSMutableArray *dataArray = [NSMutableArray array];
NSInteger count = [self getSheetAttributesWithSheet:sheetName].count;
NSLog(@"%ld",(long)count);
//sql
NSString *targetsql = [NSString stringWithFormat:@"SELECT * FROM \"%@\" Where %@",sheetName,condition] ;
NSLog(@"%@",targetsql);
//
sqlite3_stmt *ppStmt = NULL;
int result = sqlite3_prepare_v2(_sqlite, [targetsql UTF8String], -1, &ppStmt, NULL);
if (result != SQLITE_OK) {
NSLog(@"");
return nil;
}
//Sql
int hasData = sqlite3_step(ppStmt);
NSLog(@"%d",hasData);
//
while (hasData == SQLITE_ROW) {
//
const unsigned char *str;
NSMutableArray *dataModel = [NSMutableArray array];
for (int i = 0 ; i < count; i++) {
str = sqlite3_column_text(ppStmt, i); //
if (str == NULL) {
[dataModel addObject:@""];
}
else{
[dataModel addObject:[NSString stringWithUTF8String:(const char*)str]];
}
}
//Model
[dataArray addObject:dataModel];
//
hasData = sqlite3_step(ppStmt);
}
NSLog(@" = %@",dataArray);
sqlite3_finalize(ppStmt);
return dataArray;
}
- (BOOL)deleateDataFromSheet:(NSString *)sheetName where:(NSString *)condition{
if (!sheetName || !condition) {
NSLog(@"error:");
return NO;
}
NSString *targetSql = [NSString stringWithFormat:@"DELETE FROM \"%@\" WHERE %@",sheetName,condition];
NSLog(@":%@",targetSql);
//SQL
char *error = NULL;
int result = sqlite3_exec(_sqlite, [targetSql UTF8String], NULL, NULL, &error);
if (result != SQLITE_OK) {
NSLog(@"error:%s",error);
return NO;
}
NSLog(@"");
return YES;
}
- (BOOL)updateDataToSheet:(NSString *)sheetName withData:(NSArray *)data where:(NSString *)condition{
//
LCCSqliteManager *_manager = [LCCSqliteManager shareInstance];
NSArray *attributes = [_manager getSheetAttributesWithSheet:sheetName];
if (data.count != attributes.count) {
NSLog(@"");
return NO;
}
if(!data || !condition){
NSLog(@"error:");
return NO;
}
//
NSString *updataDataString = [[NSString alloc]init];
for (int i = 0 ; i < attributes.count; i ++) {
if (i == attributes.count - 1) {
NSString *pstr = [NSString stringWithFormat:@" \"%@\"= \'%@\' ",attributes[i], data[i]];
updataDataString = [updataDataString stringByAppendingString:pstr];
break;
}
NSString *pstr = [NSString stringWithFormat:@" \"%@\"= \'%@\' ,",attributes[i], data[i]];
updataDataString = [updataDataString stringByAppendingString:pstr];
}
//Sql
NSString *targetSql = [NSString stringWithFormat:@"UPDATE \"%@\" SET %@ WHERE %@",sheetName,updataDataString,condition];
NSLog(@":%@",targetSql);
//SQL
char *error = NULL;
int result = sqlite3_exec(_sqlite, [targetSql UTF8String], NULL, NULL, &error);
if (result != SQLITE_OK) {
NSLog(@"error:%s",error);
return NO;
}
NSLog(@"");
return YES;
}
#pragma mark - ForeignKey
//
- (BOOL)openForeignkey{
//sql
NSString *targetSql = [NSString stringWithFormat:@"PRAGMA foreign_keys = ON"];
//sql
char *error = NULL;
int result = sqlite3_exec(_sqlite, [targetSql UTF8String], NULL, NULL, &error);
if (result != SQLITE_OK) {
NSLog(@":%s", error);
return NO;
}
NSLog(@"");
return YES;
}
- (BOOL)closeForeignkey{
//sql
NSString *targetSql = [NSString stringWithFormat:@"PRAGMA foreign_keys = OFF"];
//sql
char *error = NULL;
int result = sqlite3_exec(_sqlite, [targetSql UTF8String], NULL, NULL, &error);
if (result != SQLITE_OK) {
NSLog(@":%s", error);
return NO;
}
NSLog(@"");
return YES;
}
#pragma mark - Auxiliary function
- (NSString *)conditionExchange:(NSString *)oldcondition{
NSString *newCondition = [oldcondition stringByReplacingOccurrencesOfString:@"" withString:@"\""];
newCondition = [newCondition stringByReplacingOccurrencesOfString:@"" withString:@"\""];
return newCondition;
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/12 - DataPersistence(数据持久化)/W3C/LCCSqliteManager/Tools/LCCSqliteManager/LCCSqliteManager.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 4,376 |
```objective-c
//
// YFLabelViewController.h
// BigShow1949
//
// Created by zhht01 on 16/3/22.
//
#import "BaseTableViewController.h"
@interface YFLabelViewController : BaseTableViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/YFLabelViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 53 |
```objective-c
//
// YFSphereTagCloud.m
// BigShow1949
//
// Created by zhht01 on 16/3/22.
//
#import "YFSphereTagCloud.h"
#import "DBSphereView.h"
@interface YFSphereTagCloud ()
@property (nonatomic, retain) DBSphereView *sphereView;
@end
@implementation YFSphereTagCloud
@synthesize sphereView;
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
sphereView = [[DBSphereView alloc] initWithFrame:CGRectMake(0, 100, 320, 320)];
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:0];
for (NSInteger i = 0; i < 50; i ++) {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
[btn setTitle:[NSString stringWithFormat:@"P%zd", i] forState:UIControlStateNormal];
[btn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
btn.titleLabel.font = [UIFont systemFontOfSize:24.];
btn.frame = CGRectMake(0, 0, 60, 20);
[btn addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[array addObject:btn];
[sphereView addSubview:btn];
}
[sphereView setCloudTags:array];
sphereView.backgroundColor = [UIColor lightGrayColor];
[self.view addSubview:sphereView];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)buttonPressed:(UIButton *)btn
{
[sphereView timerStop];
[UIView animateWithDuration:0.3 animations:^{
btn.transform = CGAffineTransformMakeScale(2., 2.);
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.3 animations:^{
btn.transform = CGAffineTransformMakeScale(1., 1.);
} completion:^(BOOL finished) {
[sphereView timerStart];
}];
}];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/SphereTagCloud/YFSphereTagCloud.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 428 |
```objective-c
//
// DBSphereView.h
// sphereTagCloud
//
// Created by Xinbao Dong on 14/8/31.
//
#import <UIKit/UIKit.h>
@interface DBSphereView : UIView
/**
* Sets the cloud's tag views.
*
* @remarks Any @c UIView subview can be passed in the array.
*
* @param array The array of tag views.
*/
- (void)setCloudTags:(NSArray *)array;
/**
* Starts the cloud autorotation animation.
*/
- (void)timerStart;
/**
* Stops the cloud autorotation animation.
*/
- (void)timerStop;
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/SphereTagCloud/DBSphereTagCloud/DBSphereView.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 135 |
```objective-c
//
// YFSphereTagCloud.h
// BigShow1949
//
// Created by zhht01 on 16/3/22.
//
#import <UIKit/UIKit.h>
@interface YFSphereTagCloud : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/SphereTagCloud/YFSphereTagCloud.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 52 |
```objective-c
//
// DBPoint.h
// sphereTagCloud
//
// Created by Xinbao Dong on 14/8/31.
//
#ifndef sphereTagCloud_DBPoint_h
#define sphereTagCloud_DBPoint_h
struct DBPoint {
CGFloat x;
CGFloat y;
CGFloat z;
};
typedef struct DBPoint DBPoint;
DBPoint DBPointMake(CGFloat x, CGFloat y, CGFloat z) {
DBPoint point;
point.x = x;
point.y = y;
point.z = z;
return point;
}
#endif
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/SphereTagCloud/DBSphereTagCloud/DBPoint.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 117 |
```objective-c
//
// DBSphereView.m
// sphereTagCloud
//
// Created by Xinbao Dong on 14/8/31.
//
#import "DBSphereView.h"
#import "DBMatrix.h"
@interface DBSphereView() <UIGestureRecognizerDelegate>
@end
@implementation DBSphereView
{
NSMutableArray *tags;
NSMutableArray *coordinate;
DBPoint normalDirection;
CGPoint last;
CGFloat velocity;
CADisplayLink *timer;
CADisplayLink *inertia;
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
UIPanGestureRecognizer *gesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
[self addGestureRecognizer:gesture];
}
return self;
}
#pragma mark - initial set
- (void)setCloudTags:(NSArray *)array
{
tags = [NSMutableArray arrayWithArray:array];
coordinate = [[NSMutableArray alloc] initWithCapacity:0];
// view,
for (NSInteger i = 0; i < tags.count; i ++) {
UIView *view = [tags objectAtIndex:i];
view.center = CGPointMake(self.frame.size.width / 2., self.frame.size.height / 2.);
}
CGFloat p1 = M_PI * (3 - sqrt(5));
CGFloat p2 = 2. / tags.count;
NSLog(@"p1:%f p2:%f", p1, p2);
for (NSInteger i = 0; i < tags.count; i ++) {
CGFloat y = i * p2 - 1 + (p2 / 2);
CGFloat r = sqrt(1 - y * y);
CGFloat p3 = i * p1;
CGFloat x = cos(p3) * r;
CGFloat z = sin(p3) * r;
DBPoint point = DBPointMake(x, y, z);
NSValue *value = [NSValue value:&point withObjCType:@encode(DBPoint)];
[coordinate addObject:value];
NSLog(@"x:%f y:%f z:%f", point.x, point.y, point.z);
CGFloat time = (arc4random() % 10 + 10.) / 20.;
[UIView animateWithDuration:time delay:0. options:UIViewAnimationOptionCurveEaseOut animations:^{
[self setTagOfPoint:point andIndex:i];
} completion:^(BOOL finished) {
}];
}
NSInteger a = arc4random() % 10 - 5;
NSInteger b = arc4random() % 10 - 5;
normalDirection = DBPointMake(a, b, 0);
[self timerStart];
}
#pragma mark - set frame of point
- (void)updateFrameOfPoint:(NSInteger)index direction:(DBPoint)direction andAngle:(CGFloat)angle
{
NSValue *value = [coordinate objectAtIndex:index];
DBPoint point;
[value getValue:&point];
DBPoint rPoint = DBPointMakeRotation(point, direction, angle);
value = [NSValue value:&rPoint withObjCType:@encode(DBPoint)];
coordinate[index] = value;
[self setTagOfPoint:rPoint andIndex:index];
}
- (void)setTagOfPoint: (DBPoint)point andIndex:(NSInteger)index
{
UIView *view = [tags objectAtIndex:index];
view.center = CGPointMake((point.x + 1) * (self.frame.size.width / 2.), (point.y + 1) * self.frame.size.width / 2.);
CGFloat transform = (point.z + 2) / 3;
view.transform = CGAffineTransformScale(CGAffineTransformIdentity, transform, transform);
view.layer.zPosition = transform;
view.alpha = transform;
if (point.z < 0) {
view.userInteractionEnabled = NO;
}else {
view.userInteractionEnabled = YES;
}
}
#pragma mark - autoTurnRotation
- (void)timerStart
{
timer = [CADisplayLink displayLinkWithTarget:self selector:@selector(autoTurnRotation)];
[timer addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
}
- (void)timerStop
{
[timer invalidate];
timer = nil;
}
- (void)autoTurnRotation
{
for (NSInteger i = 0; i < tags.count; i ++) {
[self updateFrameOfPoint:i direction:normalDirection andAngle:0.002];
}
}
#pragma mark - inertia
- (void)inertiaStart
{
[self timerStop];
inertia = [CADisplayLink displayLinkWithTarget:self selector:@selector(inertiaStep)];
[inertia addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
}
- (void)inertiaStop
{
[inertia invalidate];
inertia = nil;
[self timerStart];
}
- (void)inertiaStep
{
if (velocity <= 0) {
[self inertiaStop];
}else {
velocity -= 70.;
CGFloat angle = velocity / self.frame.size.width * 2. * inertia.duration;
for (NSInteger i = 0; i < tags.count; i ++) {
[self updateFrameOfPoint:i direction:normalDirection andAngle:angle];
}
}
}
#pragma mark - gesture selector
- (void)handlePanGesture:(UIPanGestureRecognizer *)gesture
{
if (gesture.state == UIGestureRecognizerStateBegan) {
last = [gesture locationInView:self];
[self timerStop];
[self inertiaStop];
}else if (gesture.state == UIGestureRecognizerStateChanged) {
CGPoint current = [gesture locationInView:self];
DBPoint direction = DBPointMake(last.y - current.y, current.x - last.x, 0);
CGFloat distance = sqrt(direction.x * direction.x + direction.y * direction.y);
CGFloat angle = distance / (self.frame.size.width / 2.);
for (NSInteger i = 0; i < tags.count; i ++) {
[self updateFrameOfPoint:i direction:direction andAngle:angle];
}
normalDirection = direction;
last = current;
}else if (gesture.state == UIGestureRecognizerStateEnded) {
CGPoint velocityP = [gesture velocityInView:self];
velocity = sqrt(velocityP.x * velocityP.x + velocityP.y * velocityP.y);
[self inertiaStart];
}
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/SphereTagCloud/DBSphereTagCloud/DBSphereView.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 1,367 |
```objective-c
//
// DBMatrix.h
// sphereTagCloud
//
// Created by Xinbao Dong on 14/8/31.
//
#ifndef sphereTagCloud_DBMatrix_h
#define sphereTagCloud_DBMatrix_h
#import "DBPoint.h"
struct DBMatrix {
NSInteger column;
NSInteger row;
CGFloat matrix[4][4];
};
typedef struct DBMatrix DBMatrix;
static DBMatrix DBMatrixMake(NSInteger column, NSInteger row) {
DBMatrix matrix;
matrix.column = column;
matrix.row = row;
for(NSInteger i = 0; i < column; i++){
for(NSInteger j = 0; j < row; j++){
matrix.matrix[i][j] = 0;
}
}
return matrix;
}
static DBMatrix DBMatrixMakeFromArray(NSInteger column, NSInteger row, CGFloat *data) {
DBMatrix matrix = DBMatrixMake(column, row);
for (int i = 0; i < column; i ++) {
CGFloat *t = data + (i * row);
for (int j = 0; j < row; j++) {
matrix.matrix[i][j] = *(t + j);
}
}
return matrix;
}
static DBMatrix DBMatrixMutiply(DBMatrix a, DBMatrix b) {
DBMatrix result = DBMatrixMake(a.column, b.row);
for(NSInteger i = 0; i < a.column; i ++){
for(NSInteger j = 0; j < b.row; j ++){
for(NSInteger k = 0; k < a.row; k++){
result.matrix[i][j] += a.matrix[i][k] * b.matrix[k][j];
}
}
}
return result;
}
static DBPoint DBPointMakeRotation(DBPoint point, DBPoint direction, CGFloat angle) {
// CGFloat temp1[4] = {direction.x, direction.y, direction.z, 1};
// DBMatrix directionM = DBMatrixMakeFromArray(1, 4, temp1);
if (angle == 0) {
return point;
}
CGFloat temp2[1][4] = {point.x, point.y, point.z, 1};
// DBMatrix pointM = DBMatrixMakeFromArray(1, 4, *temp2);
DBMatrix result = DBMatrixMakeFromArray(1, 4, *temp2);
if (direction.z * direction.z + direction.y * direction.y != 0) {
CGFloat cos1 = direction.z / sqrt(direction.z * direction.z + direction.y * direction.y);
CGFloat sin1 = direction.y / sqrt(direction.z * direction.z + direction.y * direction.y);
CGFloat t1[4][4] = {{1, 0, 0, 0}, {0, cos1, sin1, 0}, {0, -sin1, cos1, 0}, {0, 0, 0, 1}};
DBMatrix m1 = DBMatrixMakeFromArray(4, 4, *t1);
result = DBMatrixMutiply(result, m1);
}
if (direction.x * direction.x + direction.y * direction.y + direction.z * direction.z != 0) {
CGFloat cos2 = sqrt(direction.y * direction.y + direction.z * direction.z) / sqrt(direction.x * direction.x + direction.y * direction.y + direction.z * direction.z);
CGFloat sin2 = -direction.x / sqrt(direction.x * direction.x + direction.y * direction.y + direction.z * direction.z);
CGFloat t2[4][4] = {{cos2, 0, -sin2, 0}, {0, 1, 0, 0}, {sin2, 0, cos2, 0}, {0, 0, 0, 1}};
DBMatrix m2 = DBMatrixMakeFromArray(4, 4, *t2);
result = DBMatrixMutiply(result, m2);
}
CGFloat cos3 = cos(angle);
CGFloat sin3 = sin(angle);
CGFloat t3[4][4] = {{cos3, sin3, 0, 0}, {-sin3, cos3, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}};
DBMatrix m3 = DBMatrixMakeFromArray(4, 4, *t3);
result = DBMatrixMutiply(result, m3);
if (direction.x * direction.x + direction.y * direction.y + direction.z * direction.z != 0) {
CGFloat cos2 = sqrt(direction.y * direction.y + direction.z * direction.z) / sqrt(direction.x * direction.x + direction.y * direction.y + direction.z * direction.z);
CGFloat sin2 = -direction.x / sqrt(direction.x * direction.x + direction.y * direction.y + direction.z * direction.z);
CGFloat t2_[4][4] = {{cos2, 0, sin2, 0}, {0, 1, 0, 0}, {-sin2, 0, cos2, 0}, {0, 0, 0, 1}};
DBMatrix m2_ = DBMatrixMakeFromArray(4, 4, *t2_);
result = DBMatrixMutiply(result, m2_);
}
if (direction.z * direction.z + direction.y * direction.y != 0) {
CGFloat cos1 = direction.z / sqrt(direction.z * direction.z + direction.y * direction.y);
CGFloat sin1 = direction.y / sqrt(direction.z * direction.z + direction.y * direction.y);
CGFloat t1_[4][4] = {{1, 0, 0, 0}, {0, cos1, -sin1, 0}, {0, sin1, cos1, 0}, {0, 0, 0, 1}};
DBMatrix m1_ = DBMatrixMakeFromArray(4, 4, *t1_);
result = DBMatrixMutiply(result, m1_);
}
DBPoint resultPoint = DBPointMake(result.matrix[0][0], result.matrix[0][1], result.matrix[0][2]);
return resultPoint;
}
#endif
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/SphereTagCloud/DBSphereTagCloud/DBMatrix.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 1,353 |
```objective-c
//
// UIImage+Extend.m
// 02-
//
// Created by Apple on 15/5/27.
//
#import "UIImage+Extend.h"
#import <objc/runtime.h>
@implementation UIImage (Extend)
static char imageX;
static char imageY;
static char directions;
- (void)setX:(CGFloat)x {
// objc_setAssociatedObject
objc_setAssociatedObject(self, &imageX, [NSString stringWithFormat:@"%f",x], OBJC_ASSOCIATION_COPY);
}
- (CGFloat)x {
return [objc_getAssociatedObject(self, &imageX) floatValue];
}
- (void)setY:(CGFloat)y {
// objc_setAssociatedObject
objc_setAssociatedObject(self, &imageY, [NSString stringWithFormat:@"%f",y], OBJC_ASSOCIATION_COPY);
}
- (CGFloat)y {
return [objc_getAssociatedObject(self, &imageY) floatValue];
}
- (void)setDirection:(CZImageDirection)direction {
// objc_setAssociatedObject
objc_setAssociatedObject(self, &directions, [NSString stringWithFormat:@"%d",direction], OBJC_ASSOCIATION_COPY);
}
- (CZImageDirection)direction {
return [objc_getAssociatedObject(self, &directions) boolValue];
}
@end
//
// path_to_url (cn) path_to_url (en)
// : Code4App.com
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/Marquee/UIImage+Extend.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 285 |
```objective-c
//
// GZView.h
// Picture
//
// Created by demo on 16/1/21.
//
#import <UIKit/UIKit.h>
@interface GZView : UIView
@end
//
// path_to_url (cn) path_to_url (en)
// : Code4App.com
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/Marquee/GZView.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 64 |
```objective-c
//
// YFCycleView.m
// BigShow1949
//
// Created by zhht01 on 16/3/22.
//
#import "YFCycleView.h"
@interface YFCycleView ()
@property(nonatomic,weak) UILabel *rollLabel;
@property(nonatomic,strong) NSTimer* timer;//
@end
@implementation YFCycleView
- (instancetype)init
{
self = [super init];
if (self) {
[self makeContentView];
}
return self;
}
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self makeContentView];
// NSTimerUIImageView
self.timer = [NSTimer scheduledTimerWithTimeInterval:0.1
target:self selector:@selector(changePosition)
userInfo:nil repeats:YES];
}
return self;
}
- (void)makeContentView {
UILabel *rollLabel = [[UILabel alloc] init];
rollLabel.font = [UIFont boldSystemFontOfSize:17];
NSString *str = @""; //123456789abcdefghijklmnopqrstuvwxyzinginginginginginginginginginginginginginging
rollLabel.text = str;
CGSize rollLabelMaxSize = CGSizeMake(MAXFLOAT, self.frame.size.height);
CGSize rollLabelSize = [self sizeWithText:rollLabel.text andFont:rollLabel.font andMaxSize:rollLabelMaxSize];
CGFloat rollX = self.frame.size.width;
CGFloat rollY = 0;
NSLog(@"width = %f", rollLabelSize.width); // 1457.18 / 2 = 728.56 + 320 = 1048.45
rollLabel.frame = CGRectMake(rollX, rollY, rollLabelSize.width, rollLabelSize.height);
rollLabel.backgroundColor = [UIColor blueColor];
[rollLabel setTextColor:[UIColor redColor]];
self.rollLabel = rollLabel;
//
[self addSubview:rollLabel];
}
//iv.center
- (void)changePosition {
CGPoint curPos = self.rollLabel.center;
NSLog(@"curPos.x = %f", curPos.x);
// curPosx
if(curPos.x < -100)
{
CGFloat jianJu = self.rollLabel.frame.size.width/2;
self.rollLabel.center = CGPointMake(self.frame.size.width + jianJu, 20);
}
else
{
self.rollLabel.center = CGPointMake(curPos.x - 4, 20);
}
}
- (CGSize)sizeWithText:(NSString *)text andFont:(UIFont *)font andMaxSize:(CGSize)maxSize {
NSDictionary *atts = @{NSFontAttributeName : font};
return [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:atts context:nil].size;
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/Marquee/YFCycleView.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 601 |
```objective-c
//
// YFMarqueeViewController.h
// BigShow1949
//
// Created by zhht01 on 16/3/22.
//
#import <UIKit/UIKit.h>
@interface YFMarqueeViewController : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/Marquee/YFMarqueeViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 52 |
```objective-c
//
// YFMarqueeViewController.m
// BigShow1949
//
// Created by zhht01 on 16/3/22.
//
#import "YFMarqueeViewController.h"
#import "GZView.h"
#import "YFCycleView.h"
@interface YFMarqueeViewController ()
@property(nonatomic,strong) NSTimer* timer;//
@property(nonatomic,weak) UILabel *customLab;
@property(nonatomic,strong) UIView *viewAnima; //
@end
@implementation YFMarqueeViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
// self.navigationController.navigationBar.tintColor = [UIColor redColor];
//
// [self.navigationController.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
//*******
// [self addMiddleTitleView];
// // NSTimerUIImageView
// self.timer = [NSTimer scheduledTimerWithTimeInterval:0.1
// target:self selector:@selector(changePos)
// userInfo:nil repeats:YES];
YFCycleView *cycleView = [[YFCycleView alloc] initWithFrame:CGRectMake(0, 64, YFScreen.width, 40)];
cycleView.backgroundColor = [UIColor lightGrayColor];
[self.view addSubview:cycleView];
//*****************************
// GZView *viewAnim = [[GZView alloc] init];
// viewAnim.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
// [view addSubview:viewAnim];
}
//
-(void) addMiddleTitleView
{
//
CGFloat viewX = (self.view.frame.size.width-200)/2;
UIView *viewAnima = [[UIView alloc] initWithFrame:CGRectMake(viewX, 100, 200, 40)];
viewAnima.backgroundColor = [UIColor whiteColor];
self.viewAnima = viewAnima;
//
// [self.view addSubview:viewAnima];
self.navigationItem.titleView = self.viewAnima;
CGFloat customLabY = (self.viewAnima.frame.size.height - 30)/2;
UILabel *customLab = [[UILabel alloc] init];
customLab.frame = CGRectMake(self.viewAnima.frame.size.width, customLabY, 250, 30);
[customLab setTextColor:[UIColor redColor]];
[customLab setText:@""];
customLab.font = [UIFont boldSystemFontOfSize:17];
self.customLab = customLab;
//
[self.viewAnima addSubview:customLab];
}
//iv.center
- (void) changePos
{
CGPoint curPos = self.customLab.center;
// curPosx
if(curPos.x < -100)
{
CGFloat jianJu = self.customLab.frame.size.width/2;
//
self.customLab.center = CGPointMake(self.viewAnima.frame.size.width + jianJu, 20);
}
else
{
// ivcenteriv
self.customLab.center = CGPointMake(curPos.x - 4, 20);
}
//iv.center
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/Marquee/YFMarqueeViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 656 |
```objective-c
//
// UIImage+Extend.h
// 02-
//
// Created by Apple on 15/5/27.
//
#import <UIKit/UIKit.h>
typedef enum {
CZImageDirectionLeft, // 0
CZImageDirectionRight, // 1
}CZImageDirection;
@interface UIImage (Extend)
@property (nonatomic,assign) CGFloat x;
@property (nonatomic,assign) CGFloat y;
//
@property (nonatomic,assign) CZImageDirection direction;
@end
//
// path_to_url (cn) path_to_url (en)
// : Code4App.com
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/Marquee/UIImage+Extend.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 122 |
```objective-c
//
// YFCycleView.h
// BigShow1949
//
// Created by zhht01 on 16/3/22.
//
#import <UIKit/UIKit.h>
@interface YFCycleView : UIView
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/Marquee/YFCycleView.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 50 |
```objective-c
//
// GZView.m
// Picture
//
// Created by demo on 16/1/21.
//
#import "GZView.h"
#import "UIImage+Extend.h"
@interface GZView()
/**
*
*/
@property (nonatomic,strong) NSMutableArray *images;
/**
*
*/
@property (nonatomic,strong) NSMutableArray *deleteImages;
@end
@implementation GZView
- (NSMutableArray *)images {
if (_images == nil) {
_images = [NSMutableArray array];
}
return _images;
}
- (NSMutableArray *)deleteImages {
if (_deleteImages == nil) {
_deleteImages = [NSMutableArray array];
}
return _deleteImages;
}
//
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if(self)
{
//
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(setupImage) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
}
return self;
}
- (void)drawRect:(CGRect)rect {
for (UIImage *image in self.images) {
if (image.direction == CZImageDirectionLeft) { //
image.x -= 10;
} else { //
image.x += 10;
}
// x
image.y += arc4random_uniform(10) + 10;
[image drawAtPoint:CGPointMake(image.x, image.y)];
// x- 0
if(image.x >= rect.size.width - image.size.width || image.x <= 0) {
//
image.direction = !image.direction;
}
// y
//
if(image.y > rect.size.height) {
[self.deleteImages addObject:image];
}
}
//
for (UIImage *image in self.deleteImages) {
[self.images removeObject:image];
}
[self.deleteImages removeAllObjects];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(setupImage) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
}
- (void)setupImage {
if (self.images.count < 10) {
//
// UIImage *image = [UIImage imageNamed:@"gift"]; //
UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"gift@2x.png" ofType:nil]];
image.x = arc4random_uniform(self.frame.size.width - image.size.width);
image.direction = arc4random_uniform(2);// 0,1
[self.images addObject:image];
}
//
[self setNeedsDisplay];
}
@end
//
// path_to_url (cn) path_to_url (en)
// : Code4App.com
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/Marquee/GZView.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 638 |
```objective-c
//
// YFAutolayoutTagViewController.h
// BigShow1949
//
// Created by zhht01 on 16/3/22.
//
#import <UIKit/UIKit.h>
@interface YFAutolayoutTagViewController : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/AutolayoutTagView/YFAutolayoutTagViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 56 |
```objective-c
//
// YFAutolayoutTagViewController.m
// BigShow1949
//
// Created by zhht01 on 16/3/22.
//
#import "YFAutolayoutTagViewController.h"
#import "SKTagView.h"
//#import <Masonry/Masonry.h>
//#import <HexColors/HexColors.h>
#import "UIColor+Extension.h"
#import "Masonry.h"
@interface YFAutolayoutTagViewController ()
@property (strong, nonatomic) SKTagView *tagView;
@property (strong, nonatomic) NSArray *colors;
@property (weak, nonatomic) IBOutlet UITextField *index;
@end
@implementation YFAutolayoutTagViewController
#pragma mark - Lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
self.colors = @[@"#7ecef4", @"#84ccc9", @"#88abda", @"#7dc1dd", @"#b6b8de"];
[self setupTagView];
}
#pragma mark - Private
- (void)setupTagView {
self.tagView = ({
SKTagView *view = [SKTagView new];
view.backgroundColor = [UIColor whiteColor];
view.padding = UIEdgeInsetsMake(12, 12, 12, 12);
view.interitemSpacing = 15;
view.lineSpacing = 10;
__weak SKTagView *weakView = view;
view.didTapTagAtIndex = ^(NSUInteger index){
[weakView removeTagAtIndex:index];
};
view;
});
[self.view addSubview:self.tagView];
[self.tagView mas_makeConstraints: ^(MASConstraintMaker *make) {
UIView *superView = self.view;
make.centerY.equalTo(superView.mas_centerY).with.offset(0);
make.leading.equalTo(superView.mas_leading).with.offset(0);
make.trailing.equalTo(superView.mas_trailing);
}];
//Add Tags , @"Python", @"Swift", @"Go", @"Objective-C", @"C", @"PHP"
[@[@"Python", @"Javascript"] enumerateObjectsUsingBlock: ^(NSString *text, NSUInteger idx, BOOL *stop) {
SKTag *tag = [SKTag tagWithText: text];
tag.textColor = [UIColor whiteColor];
tag.fontSize = 15;
//tag.font = [UIFont fontWithName:@"Courier" size:15];
//tag.enable = NO;
tag.padding = UIEdgeInsetsMake(13.5, 12.5, 13.5, 12.5);
tag.bgColor = [UIColor colorWithHexString:self.colors[idx % self.colors.count]];
tag.cornerRadius = 5;
[self.tagView addTag:tag];
}];
}
#pragma mark - IBActions
- (IBAction)onAdd: (id)sender {
SKTag *tag = [SKTag tagWithText: @"Some Language"];
tag.textColor = [UIColor whiteColor];
tag.fontSize = 15;
tag.enable = YES;
tag.padding = UIEdgeInsetsMake(13.5, 12.5, 13.5, 12.5);
tag.bgColor = [UIColor colorWithHexString:self.colors[arc4random() % self.colors.count]];
tag.cornerRadius = 5;
[self.tagView addTag:tag];
}
- (IBAction)onInsert: (id)sender {
SKTag *tag = [SKTag tagWithText: [NSString stringWithFormat:@"Insert(%ld)",(long)self.index.text.integerValue]];
tag.textColor = [UIColor whiteColor];
tag.fontSize = 15;
tag.padding = UIEdgeInsetsMake(13.5, 12.5, 13.5, 12.5);
tag.bgColor = [UIColor colorWithHexString:self.colors[arc4random() % self.colors.count]];;
tag.cornerRadius = 5;
[self.tagView insertTag: tag atIndex: self.index.text.integerValue];
}
- (IBAction)onRemove: (id)sender {
[self.tagView removeTagAtIndex: self.index.text.integerValue];
}
- (IBAction)onTapBg: (id)sender {
[self.view endEditing: YES];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/AutolayoutTagView/YFAutolayoutTagViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 860 |
```objective-c
//
// SKTagView.h
//
// Created by Shaokang Zhao on 15/1/12.
//
#import <UIKit/UIKit.h>
#import "SKTag.h"
@interface SKTagView : UIView
@property (assign, nonatomic) UIEdgeInsets padding;
@property (assign, nonatomic) CGFloat lineSpacing;
@property (assign, nonatomic) CGFloat interitemSpacing;
@property (assign, nonatomic) CGFloat preferredMaxLayoutWidth;
@property (assign, nonatomic) BOOL singleLine;
@property (copy, nonatomic, nullable) void (^didTapTagAtIndex)(NSUInteger index);
- (void)addTag: (nonnull SKTag *)tag;
- (void)insertTag: (nonnull SKTag *)tag atIndex:(NSUInteger)index;
- (void)removeTag: (nonnull SKTag *)tag;
- (void)removeTagAtIndex: (NSUInteger)index;
- (void)removeAllTags;
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/AutolayoutTagView/SKTagView/SKTagView.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 184 |
```objective-c
//
// Created by Shaokang Zhao on 15/1/12.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface SKTag : NSObject
@property (copy, nonatomic, nullable) NSString *text;
@property (copy, nonatomic, nullable) NSAttributedString *attributedText;
@property (strong, nonatomic, nullable) UIColor *textColor;
///backgound color
@property (strong, nonatomic, nullable) UIColor *bgColor;
///background image
@property (strong, nonatomic, nullable) UIImage *bgImg;
@property (assign, nonatomic) CGFloat cornerRadius;
@property (strong, nonatomic, nullable) UIColor *borderColor;
@property (assign, nonatomic) CGFloat borderWidth;
///like padding in css
@property (assign, nonatomic) UIEdgeInsets padding;
@property (strong, nonatomic, nullable) UIFont *font;
///if no font is specified, system font with fontSize is used
@property (assign, nonatomic) CGFloat fontSize;
///default:YES
@property (assign, nonatomic) BOOL enable;
- (nonnull instancetype)initWithText: (nonnull NSString *)text;
+ (nonnull instancetype)tagWithText: (nonnull NSString *)text;
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/AutolayoutTagView/SKTagView/SKTag.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 240 |
```objective-c
//
// Created by Shaokang Zhao on 15/1/12.
//
#import "SKTagButton.h"
#import "SKTag.h"
@implementation SKTagButton
+ (instancetype)buttonWithTag: (SKTag *)tag {
SKTagButton *btn = [super buttonWithType:UIButtonTypeCustom];
if (tag.attributedText) {
[btn setAttributedTitle: tag.attributedText forState: UIControlStateNormal];
} else {
[btn setTitle: tag.text forState:UIControlStateNormal];
[btn setTitleColor: tag.textColor forState: UIControlStateNormal];
btn.titleLabel.font = tag.font ?: [UIFont systemFontOfSize: tag.fontSize];
}
btn.backgroundColor = tag.bgColor;
btn.contentEdgeInsets = tag.padding;
btn.titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
if (tag.bgImg) {
[btn setBackgroundImage: tag.bgImg forState: UIControlStateNormal];
}
if (tag.borderColor) {
btn.layer.borderColor = tag.borderColor.CGColor;
}
if (tag.borderWidth) {
btn.layer.borderWidth = tag.borderWidth;
}
btn.userInteractionEnabled = tag.enable;
btn.layer.cornerRadius = tag.cornerRadius;
btn.layer.masksToBounds = YES;
return btn;
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/AutolayoutTagView/SKTagView/SKTagButton.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 260 |
```objective-c
//
// Created by Shaokang Zhao on 15/1/12.
//
#import "SKTag.h"
static const CGFloat kDefaultFontSize = 13.0;
@implementation SKTag
- (instancetype)init {
self = [super init];
if (self) {
_fontSize = kDefaultFontSize;
_textColor = [UIColor blackColor];
_bgColor = [UIColor whiteColor];
_enable = YES;
}
return self;
}
- (instancetype)initWithText: (NSString *)text {
self = [self init];
if (self) {
_text = text;
}
return self;
}
+ (instancetype)tagWithText: (NSString *)text {
return [[self alloc] initWithText: text];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/AutolayoutTagView/SKTagView/SKTag.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 160 |
```objective-c
//
// Created by Shaokang Zhao on 15/1/12.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@class SKTag;
@interface SKTagButton: UIButton
+ (nonnull instancetype)buttonWithTag: (nonnull SKTag *)tag;
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/AutolayoutTagView/SKTagView/SKTagButton.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 59 |
```objective-c
//
// YFPrinterEffectViewController.m
// BigShow1949
//
// Created by zhht01 on 16/3/17.
//
#import "YFPrinterEffectViewController.h"
#import "ZTypewriteEffectLabel.h"
@interface YFPrinterEffectViewController ()
@end
@implementation YFPrinterEffectViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = [UIColor blackColor];
ZTypewriteEffectLabel *myLbl = [[ZTypewriteEffectLabel alloc] initWithFrame:CGRectMake(5, 30, 310, 450)];
myLbl.tag = 10;
myLbl.backgroundColor = [UIColor clearColor];
myLbl.numberOfLines = 0;
myLbl.text = @"\t\t\t\n\n\tCode4App \n\n\t App \n\n\tCode4AppCode4App Code4App \n\n\t\t\t\t\t\t\t\tBy\tZ ";
myLbl.textColor = self.view.backgroundColor;
myLbl.typewriteEffectColor = [UIColor greenColor];
myLbl.hasSound = YES;
myLbl.typewriteTimeInterval = 0.3;
myLbl.typewriteEffectBlock = ^{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
};
[self.view addSubview:myLbl];
/** Z
* 1
*/
[self performSelector:@selector(startOutPut) withObject:nil afterDelay:1];
}
-(void)startOutPut
{
ZTypewriteEffectLabel *myLbl = (ZTypewriteEffectLabel *)[self.view viewWithTag:10];
[myLbl startTypewrite];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/PrinterEffect/YFPrinterEffectViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 414 |
```objective-c
//
// ZTypewriteEffectLabel.m
// ZTypewriteEffect
//
// Created by mapboo on 7/27/14.
//
#import "ZTypewriteEffectLabel.h"
@implementation ZTypewriteEffectLabel
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.hasSound = YES;
self.typewriteTimeInterval = 0.3;
}
return self;
}
-(void)startTypewrite
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"typewriter" ofType:@"wav"];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:path], &soundID);
[NSTimer scheduledTimerWithTimeInterval:self.typewriteTimeInterval target:self selector:@selector(outPutWord:) userInfo:nil repeats:YES];
}
-(void)outPutWord:(id)atimer
{
if (self.text.length == self.currentIndex) {
[atimer invalidate];
atimer = nil;
self.typewriteEffectBlock();
}else{
self.currentIndex++;
NSDictionary *dic = @{NSForegroundColorAttributeName: self.typewriteEffectColor};
NSMutableAttributedString *mutStr = [[NSMutableAttributedString alloc] initWithString:self.text];
[mutStr addAttributes:dic range:NSMakeRange(0, self.currentIndex)];
[self setAttributedText:mutStr];
self.hasSound? AudioServicesPlaySystemSound (soundID):AudioServicesPlaySystemSound (0);
}
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/PrinterEffect/ZTypewriteEffectLabel.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 372 |
```objective-c
//
// YFPrinterEffectViewController.h
// BigShow1949
//
// Created by zhht01 on 16/3/17.
//
#import <UIKit/UIKit.h>
@interface YFPrinterEffectViewController : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/PrinterEffect/YFPrinterEffectViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 52 |
```objective-c
//
// SKTagView.m
//
// Created by Shaokang Zhao on 15/1/12.
//
#import "SKTagView.h"
#import "SKTagButton.h"
@interface SKTagView ()
@property (strong, nonatomic, nullable) NSMutableArray *tags;
@property (assign, nonatomic) BOOL didSetup;
@end
@implementation SKTagView
#pragma mark - Lifecycle
-(CGSize)intrinsicContentSize {
if (!self.tags.count) {
return CGSizeZero;
}
NSArray *subviews = self.subviews;
UIView *previousView = nil;
CGFloat topPadding = self.padding.top;
CGFloat bottomPadding = self.padding.bottom;
CGFloat leftPadding = self.padding.left;
CGFloat rightPadding = self.padding.right;
CGFloat itemSpacing = self.interitemSpacing;
CGFloat lineSpacing = self.lineSpacing;
CGFloat currentX = leftPadding;
CGFloat intrinsicHeight = topPadding;
CGFloat intrinsicWidth = leftPadding;
if (!self.singleLine && self.preferredMaxLayoutWidth > 0) {
NSInteger lineCount = 0;
for (UIView *view in subviews) {
CGSize size = view.intrinsicContentSize;
if (previousView) {
CGFloat width = size.width;
currentX += itemSpacing;
if (currentX + width + rightPadding <= self.preferredMaxLayoutWidth) {
currentX += size.width;
} else {
lineCount ++;
currentX = leftPadding + size.width;
intrinsicHeight += size.height;
}
} else {
lineCount ++;
intrinsicHeight += size.height;
currentX += size.width;
}
previousView = view;
intrinsicWidth = MAX(intrinsicWidth, currentX + rightPadding);
}
intrinsicHeight += bottomPadding + lineSpacing * (lineCount - 1);
} else {
for (UIView *view in subviews) {
CGSize size = view.intrinsicContentSize;
intrinsicWidth += size.width;
}
intrinsicWidth += itemSpacing * (subviews.count - 1) + rightPadding;
intrinsicHeight += ((UIView *)subviews.firstObject).intrinsicContentSize.height + bottomPadding;
}
return CGSizeMake(intrinsicWidth, intrinsicHeight);
}
- (void)layoutSubviews {
if (!self.singleLine) {
self.preferredMaxLayoutWidth = self.frame.size.width;
}
[super layoutSubviews];
[self layoutTags];
}
#pragma mark - Custom accessors
- (NSMutableArray *)tags {
if(!_tags) {
_tags = [NSMutableArray array];
}
return _tags;
}
- (void)setPreferredMaxLayoutWidth: (CGFloat)preferredMaxLayoutWidth {
if (preferredMaxLayoutWidth != _preferredMaxLayoutWidth) {
_preferredMaxLayoutWidth = preferredMaxLayoutWidth;
_didSetup = NO;
[self invalidateIntrinsicContentSize];
}
}
#pragma mark - Private
- (void)layoutTags {
if (self.didSetup || !self.tags.count) {
return;
}
NSArray *subviews = self.subviews;
UIView *previousView = nil;
CGFloat topPadding = self.padding.top;
CGFloat leftPadding = self.padding.left;
CGFloat rightPadding = self.padding.right;
CGFloat itemSpacing = self.interitemSpacing;
CGFloat lineSpacing = self.lineSpacing;
CGFloat currentX = leftPadding;
if (!self.singleLine && self.preferredMaxLayoutWidth > 0) {
for (UIView *view in subviews) {
NSLog(@"frame = %@", NSStringFromCGRect(view.frame));
CGSize size = view.intrinsicContentSize;
if (previousView) {
CGFloat width = size.width;
currentX += itemSpacing;
if (currentX + width + rightPadding <= self.preferredMaxLayoutWidth) {
view.frame = CGRectMake(currentX, CGRectGetMinY(previousView.frame), size.width, size.height);
currentX += size.width;
} else {
CGFloat width = MIN(size.width, self.preferredMaxLayoutWidth - leftPadding - rightPadding);
view.frame = CGRectMake(leftPadding, CGRectGetMaxY(previousView.frame) + lineSpacing, width, size.height);
currentX = leftPadding + width;
}
} else {
CGFloat width = MIN(size.width, self.preferredMaxLayoutWidth - leftPadding - rightPadding);
view.frame = CGRectMake(leftPadding, topPadding, width, size.height);
currentX += width;
}
previousView = view;
}
} else {
for (UIView *view in subviews) {
CGSize size = view.intrinsicContentSize;
view.frame = CGRectMake(currentX, topPadding, size.width, size.height);
currentX += size.width;
previousView = view;
}
}
self.didSetup = YES;
}
#pragma mark - IBActions
- (void)onTag: (UIButton *)btn {
if (self.didTapTagAtIndex) {
self.didTapTagAtIndex([self.subviews indexOfObject: btn]);
}
}
#pragma mark - Public
- (void)addTag: (SKTag *)tag {
NSParameterAssert(tag);
SKTagButton *btn = [SKTagButton buttonWithTag: tag];
[btn addTarget: self action: @selector(onTag:) forControlEvents: UIControlEventTouchUpInside];
[self addSubview: btn];
[self.tags addObject: tag];
self.didSetup = NO;
[self invalidateIntrinsicContentSize];
}
- (void)insertTag: (SKTag *)tag atIndex: (NSUInteger)index {
NSParameterAssert(tag);
if (index + 1 > self.tags.count) {
[self addTag: tag];
} else {
SKTagButton *btn = [SKTagButton buttonWithTag: tag];
[btn addTarget: self action: @selector(onTag:) forControlEvents: UIControlEventTouchUpInside];
[self insertSubview: btn atIndex: index];
[self.tags insertObject: tag atIndex: index];
self.didSetup = NO;
[self invalidateIntrinsicContentSize];
}
}
- (void)removeTag: (SKTag *)tag {
NSParameterAssert(tag);
NSUInteger index = [self.tags indexOfObject: tag];
if (NSNotFound == index) {
return;
}
[self.tags removeObjectAtIndex: index];
if (self.subviews.count > index) {
[self.subviews[index] removeFromSuperview];
}
self.didSetup = NO;
[self invalidateIntrinsicContentSize];
}
- (void)removeTagAtIndex: (NSUInteger)index {
if (index + 1 > self.tags.count) {
return;
}
[self.tags removeObjectAtIndex: index];
if (self.subviews.count > index) {
[self.subviews[index] removeFromSuperview];
}
self.didSetup = NO;
[self invalidateIntrinsicContentSize];
}
- (void)removeAllTags {
[self.tags removeAllObjects];
for (UIView *view in self.subviews) {
[view removeFromSuperview];
}
self.didSetup = NO;
[self invalidateIntrinsicContentSize];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/AutolayoutTagView/SKTagView/SKTagView.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 1,510 |
```objective-c
//
// YFDynamicLabelViewController.h
// BigShow1949
//
// Created by zhht01 on 16/3/22.
//
#import <UIKit/UIKit.h>
#include <QuartzCore/QuartzCore.h>
@interface YFDynamicLabelViewController : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/DynamicLabel/YFDynamicLabelViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 63 |
```objective-c
//
// ZTypewriteEffectLabel.h
// ZTypewriteEffect
//
// Created by mapboo on 7/27/14.
//
/**
* -
path_to_url
* Z
* iOS262091386
* - path_to_url
*/
#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>
typedef void (^ZTypewriteEffectBlock)(void);
@interface ZTypewriteEffectLabel : UILabel
{
SystemSoundID soundID;
}
/** Z
* 0.3
*/
@property (nonatomic) NSTimeInterval typewriteTimeInterval;
/** Z
* 0
*/
@property (nonatomic) int currentIndex;
/** Z
*
*/
@property (nonatomic, strong) UIColor *typewriteEffectColor;
/** Z
* , YES
*/
@property (nonatomic) BOOL hasSound;
/** Z
* block
*/
@property (nonatomic, copy) ZTypewriteEffectBlock typewriteEffectBlock;
/** Z
*
*/
-(void)startTypewrite;
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/PrinterEffect/ZTypewriteEffectLabel.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 228 |
```objective-c
//
// YFDynamicLabelViewController.m
// BigShow1949
//
// Created by zhht01 on 16/3/22.
//
#import "YFDynamicLabelViewController.h"
#import "CloudView.h"
@interface YFDynamicLabelViewController ()
@end
@implementation YFDynamicLabelViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSArray *labelARy =[NSArray arrayWithObjects:@"",@"",@"",@"",@"",@"",@"",@"",@"",@"2",@"3",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@":",@"",@"",@"",@"",@"",@"",@"101",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"2:",nil];
CloudView *cv=[[CloudView alloc] initWithFrame:CGRectMake(0, 80, 320, 320)];
[cv reloadData:labelARy];
cv.layer.borderColor=[UIColor yellowColor].CGColor;
cv.layer.borderWidth=2;
[self.view addSubview:cv];
[self.view setBackgroundColor:[UIColor darkTextColor]];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/DynamicLabel/YFDynamicLabelViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 247 |
```objective-c
//
// NSObject+KVC.m
// CloudLabel
//
// Created by PowerAuras on 13-9-6.
// qq120971999 path_to_url
//
#import "NSObject+KVC.h"
@implementation NSObject(aa)
- (id)valueForUndefinedKey:(NSString *)key{
return objc_getAssociatedObject(self, (__bridge const void *)(key));
}
- (void)setValue:(id)value forUndefinedKey:(NSString *)key{ // , ?
objc_setAssociatedObject(self, (__bridge const void *)(key), value, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/DynamicLabel/NSObject+KVC.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 132 |
```objective-c
//
// NSObject+KVC.h
// CloudLabel
//
// Created by PowerAuras on 13-9-6.
// qq120971999 path_to_url
//
#import <UIKit/UIKit.h>
#import <objc/runtime.h>
@interface NSObject (aa)
- (id)valueForUndefinedKey:(NSString *)key;
- (void)setValue:(id)value forUndefinedKey:(NSString *)key;
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/DynamicLabel/NSObject+KVC.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 90 |
```objective-c
//
// CloudView.h
// CloudLabel
//
// Created by PowerAuras on 13-9-2.
// qq120971999 path_to_url
//
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import <CoreFoundation/CoreFoundation.h>
@interface CloudView : UIView
{
// CGContextRef contex;
}
-(void)reloadData:(NSArray *)ary;
@end
@interface NSArray (Modulo)
- (id)objectAtModuloIndex:(NSUInteger)index;
@end
@interface BubbleV : UILabel
{
id delegate;
}
@property(nonatomic,assign) id delegate;
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/DynamicLabel/CloudView.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 134 |
```objective-c
//
// YFSphereViewController.m
// BigShow1949
//
// Created by zhht01 on 16/3/22.
//
#import "YFSphereViewController.h"
#import "ZYQSphereView.h"
@interface YFSphereViewController (){
ZYQSphereView *sphereView;
NSTimer *timer;
}
@end
@implementation YFSphereViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor blackColor];
sphereView = [[ZYQSphereView alloc] initWithFrame:CGRectMake(10, 60, 300, 300)];
sphereView.center=CGPointMake(self.view.center.x, self.view.center.y-30);
NSMutableArray *views = [[NSMutableArray alloc] init];
for (int i = 0; i < 50; i++) {
UIButton *subV = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
subV.backgroundColor = [UIColor colorWithRed:arc4random_uniform(100)/100. green:arc4random_uniform(100)/100. blue:arc4random_uniform(100)/100. alpha:1];
[subV setTitle:[NSString stringWithFormat:@"%d",i] forState:UIControlStateNormal];
subV.layer.masksToBounds=YES;
subV.layer.cornerRadius=3;
[subV addTarget:self action:@selector(subVClick:) forControlEvents:UIControlEventTouchUpInside];
[views addObject:subV];
}
[sphereView setItems:views];
sphereView.isPanTimerStart=YES;
[self.view addSubview:sphereView];
[sphereView timerStart];
UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
btn.frame=CGRectMake((self.view.frame.size.width-120)/2, self.view.frame.size.height-60, 120, 30);
[self.view addSubview:btn];
btn.backgroundColor=[UIColor whiteColor];
btn.layer.borderWidth=1;
btn.layer.borderColor=[[UIColor orangeColor] CGColor];
[btn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
[btn setTitle:@"start/stop" forState:UIControlStateNormal];
btn.selected=NO;
[btn addTarget:self action:@selector(changePF:) forControlEvents:UIControlEventTouchUpInside];
}
-(void)subVClick:(UIButton*)sender{
NSLog(@"%@",sender.titleLabel.text);
BOOL isStart=[sphereView isTimerStart];
[sphereView timerStop];
[UIView animateWithDuration:0.3 animations:^{
sender.transform=CGAffineTransformMakeScale(1.5, 1.5);
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.2 animations:^{
sender.transform=CGAffineTransformMakeScale(1, 1);
if (isStart) {
[sphereView timerStart];
}
}];
}];
}
-(void)changePF:(UIButton*)sender{
if ([sphereView isTimerStart]) {
[sphereView timerStop];
}
else{
[sphereView timerStart];
}
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/SphereView/YFSphereViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 622 |
```objective-c
//
// YFSphereViewController.h
// BigShow1949
//
// Created by zhht01 on 16/3/22.
//
#import <UIKit/UIKit.h>
@interface YFSphereViewController : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/SphereView/YFSphereViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 50 |
```objective-c
//This file is part of SphereView.
//
//SphereView is free software: you can redistribute it and/or modify
//(at your option) any later version.
//
//SphereView is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//
//along with SphereView. If not, see <path_to_url
#define PFMatrixMaxSize 4
struct PFMatrix {
NSInteger m;
NSInteger n;
CGFloat data[PFMatrixMaxSize][PFMatrixMaxSize];
};
typedef struct PFMatrix PFMatrix;
static PFMatrix PFMatrixMake(NSInteger m, NSInteger n) {
PFMatrix matrix;
matrix.m = m;
matrix.n = n;
for(NSInteger i=0; i<m; i++){
for(NSInteger j=0; j<n; j++){
matrix.data[i][j] = 0;
}
}
return matrix;
}
static PFMatrix PFMatrixMakeFromArray(NSInteger m, NSInteger n, CGFloat *data) {
PFMatrix matrix = PFMatrixMake(m, n);
for (int i=0; i<m; i++) {
CGFloat *t = data+(i*sizeof(CGFloat));
for (int j=0; j<n; j++) {
matrix.data[i][j] = *(t+j);
}
}
return matrix;
}
static PFMatrix PFMatrixMakeIdentity(NSInteger m, NSInteger n) {
PFMatrix matrix = PFMatrixMake(m, n);
for(NSInteger i=0; i<m; i++){
matrix.data[i][i] = 1;
}
return matrix;
}
static PFMatrix PFMatrixMultiply(PFMatrix A, PFMatrix B) {
PFMatrix R = PFMatrixMake(A.m, B.n);
for(NSInteger i=0; i<A.m; i++){
for(NSInteger j=0; j<B.n; j++){
for(NSInteger k=0; k < A.n; k++){
R.data[i][j] += A.data[i][k] * B.data[k][j];
}
}
}
return R;
}
static NSString *NSStringFromPFMatrix(PFMatrix matrix) {
NSMutableString *str = [NSMutableString string];
[str appendString:@"{"];
for(NSInteger i=0; i<matrix.m; i++){
[str appendString:@"\n{"];
for(NSInteger j=0; j<matrix.n; j++){
[str appendFormat:@"%f",matrix.data[i][j]];
if (j+1 < matrix.n) {
[str appendString:@","];
}
}
[str appendString:@"}"];
if (i+1 < matrix.m) {
[str appendString:@","];
}
}
[str appendString:@"\n}"];
return str;
}
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/SphereView/SphereView/PFMatrix.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 622 |
```objective-c
//This file is part of SphereView.
//
//SphereView is free software: you can redistribute it and/or modify
//(at your option) any later version.
//
//SphereView is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//
//along with SphereView. If not, see <path_to_url
#import "PFGoldenSectionSpiral.h"
@implementation PFGoldenSectionSpiral
+ (NSArray *)sphere:(NSInteger)n {
NSMutableArray* result = [NSMutableArray arrayWithCapacity:n];
CGFloat N = n;
CGFloat inc = M_PI * (3 - sqrt(5));
CGFloat off = 2 / N;
for (NSInteger k=0; k<N; k++) {
CGFloat y = k * off - 1 + (off / 2);
CGFloat r = sqrt(1 - y*y);
CGFloat phi = k * inc;
PFPoint point = PFPointMake(cos(phi)*r, y, sin(phi)*r);
NSValue *v = [NSValue value:&point withObjCType:@encode(PFPoint)];
[result addObject:v];
}
return result;
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/SphereView/SphereView/PFGoldenSectionSpiral.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 275 |
```objective-c
//This file is part of SphereView.
//
//SphereView is free software: you can redistribute it and/or modify
//(at your option) any later version.
//
//SphereView is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//
//along with SphereView. If not, see <path_to_url
#import <math.h>
// Parfait
#import "PFRadian.h"
#import "PFPoint.h"
#import "PFMatrix.h"
#import "PFMatrixTransform.h"
@interface PFGoldenSectionSpiral : NSObject {
}
+ (NSArray *)sphere:(NSInteger)n;
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/SphereView/SphereView/PFGoldenSectionSpiral.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 152 |
```objective-c
//This file is part of SphereView.
//
//SphereView is free software: you can redistribute it and/or modify
//(at your option) any later version.
//
//SphereView is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//
//along with SphereView. If not, see <path_to_url
typedef CGFloat PFRadian;
static PFRadian PFRadianMake(CGFloat grades) {
return (M_PI * grades / 180.0);
}
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/SphereView/SphereView/PFRadian.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 125 |
```objective-c
//This file is part of SphereView.
//
//SphereView is free software: you can redistribute it and/or modify
//(at your option) any later version.
//
//SphereView is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//
//along with SphereView. If not, see <path_to_url
typedef enum {
PFAxisDirectionNone,
PFAxisDirectionPositive = 1,
PFAxisDirectionNegative = -1
} PFAxisDirection;
static CGFloat PFAxisDirectionMinimumDistance = 0.033f;
static PFAxisDirection PFAxisDirectionMake(CGFloat fromCoordinate, CGFloat toCoordinate, BOOL sensitive) {
PFAxisDirection direction = PFAxisDirectionNone;
CGFloat distance = fabs(fromCoordinate - toCoordinate);
if (distance > PFAxisDirectionMinimumDistance || sensitive) {
if (fromCoordinate > toCoordinate) {
direction = PFAxisDirectionPositive;
} else if (fromCoordinate < toCoordinate) {
direction = PFAxisDirectionNegative;
}
}
return direction;
}
static PFAxisDirection PFDirectionMakeXAxis(CGPoint fromPoint, CGPoint toPoint) {
return PFAxisDirectionMake(fromPoint.x, toPoint.x, NO);
}
static PFAxisDirection PFDirectionMakeYAxis(CGPoint fromPoint, CGPoint toPoint) {
return PFAxisDirectionMake(fromPoint.y, toPoint.y, NO);
}
static PFAxisDirection PFDirectionMakeXAxisSensitive(CGPoint fromPoint, CGPoint toPoint) {
return PFAxisDirectionMake(fromPoint.x, toPoint.x, YES);
}
static PFAxisDirection PFDirectionMakeYAxisSensitive(CGPoint fromPoint, CGPoint toPoint) {
return PFAxisDirectionMake(fromPoint.y, toPoint.y, YES);
}
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/SphereView/SphereView/PFAxisDirection.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 404 |
```objective-c
//
// CloudView.m
// CloudLabel
//
// Created by PowerAuras on 13-9-2.
// qq120971999 path_to_url
//
#import "CloudView.h"
#define BUDDLEGAP_X 35
#define BUDDLEGAP_Y 10
#define FONTHEIGHT 35
#define DURATION 16
#define FIREINTERVAL 2
@interface CloudView ()
{
NSArray *dataARy;
NSInteger index;
}
@end
@implementation CloudView
//
-(void)touchUpInside:(UIButton *)ges{
NSLog(@"");
}
//
-(void)touchDown:(UIButton *)ges{
CFTimeInterval pausedTime = [ges.layer convertTime:CACurrentMediaTime() fromLayer:nil];
ges.layer.speed = 0.0;
ges.layer.timeOffset = pausedTime;
}
//
-(void)touchOut:(UIButton *)but{
CFTimeInterval pausedTime = [but.layer timeOffset];
but.layer.speed = 1.0;
but.layer.timeOffset = 0.0;
but.layer.beginTime = 0.0;
CFTimeInterval timeSincePause = [but.layer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime;
but.layer.beginTime = timeSincePause;
}
//
-(NSArray *)containThree{
NSInteger tempIndex=index;
NSObject *ob1=[dataARy objectAtModuloIndex:tempIndex];
CGFloat width1=[(NSString *)ob1 sizeWithFont:[UIFont systemFontOfSize:16] constrainedToSize:CGSizeMake(1000, FONTHEIGHT)].width;
++tempIndex;
NSObject *ob2=[dataARy objectAtModuloIndex:tempIndex];
CGFloat width2=[(NSString *)ob2 sizeWithFont:[UIFont systemFontOfSize:16] constrainedToSize:CGSizeMake(1000, FONTHEIGHT)].width;
++tempIndex ;
NSObject *ob3=[dataARy objectAtModuloIndex:tempIndex];
CGFloat width3=[(NSString *)ob3 sizeWithFont:[UIFont systemFontOfSize:16] constrainedToSize:CGSizeMake(1000, FONTHEIGHT)].width;
//
if (width1+width2+width3>280) {
//
if (width1+width2>280) {
++index;
return [NSArray arrayWithObject:ob1];
}else{
index+=2;
return [NSArray arrayWithObjects:ob1,ob2, nil];
}
}else{
index+=3;
return [NSArray arrayWithObjects:ob1,ob2,ob3, nil];
}
}
//
-(NSArray *)bubbleUp{
index=index%[dataARy count];
NSArray *temp= [self containThree];
NSMutableArray *butAry=[NSMutableArray array];
for (int i=0; i<[temp count]; i++) {
NSString *thstr=[temp objectAtIndex:i];
UIFont *thfont=[UIFont systemFontOfSize:16];
CGFloat thstrwidth=[thstr sizeWithFont:thfont constrainedToSize:CGSizeMake(1000, FONTHEIGHT)].width;
BubbleV *label=[[BubbleV alloc] init];
label.frame=CGRectMake(self.frame.size.width/2-thstrwidth/2, self.frame.size.height-FONTHEIGHT, thstrwidth,FONTHEIGHT);
[label setText:thstr];
label.delegate=self;
[label setFont:thfont];
[label setTextColor:[UIColor whiteColor]];
label.backgroundColor=[UIColor clearColor];
[self addSubview:label];
[butAry addObject:label];
[label release];
CGFloat index0strwidth=[[temp objectAtIndex:0] sizeWithFont:thfont constrainedToSize:CGSizeMake(1000, FONTHEIGHT)].width;
//
if ([temp count]==2) {
if (i==0) {
//
CGRect rect=label.frame;
rect.origin.x=self.frame.size.width/4-thstrwidth/2;
rect.origin.y-=FONTHEIGHT/2;
label.frame=rect;
}else if(i==1){
//
CGRect rect=label.frame;
rect.origin.x=self.frame.size.width/4*3-thstrwidth/2;
rect.origin.y-=FONTHEIGHT/2;
label.frame=rect;
}
}else{
//13
if (i==1) {
//origin.x x+width=this.origin.x
CGRect rect=label.frame;
rect.origin.x=self.frame.size.width/2-index0strwidth/2;
rect.origin.x-=(thstrwidth-BUDDLEGAP_X);
rect.origin.y-=(FONTHEIGHT-BUDDLEGAP_Y);
label.frame=rect;
}
if (i==2) {
//origin.x x+width=this.origin.x
CGRect rect=label.frame;
rect.origin.x=self.frame.size.width/2-index0strwidth/2;
rect.origin.x+=index0strwidth-BUDDLEGAP_X;
rect.origin.y-=(FONTHEIGHT-BUDDLEGAP_Y);
label.frame=rect;
}
}
CABasicAnimation *basicScale=[CABasicAnimation animationWithKeyPath:@"transform.scale"];
basicScale.fromValue=[NSNumber numberWithFloat:.65];
basicScale.toValue=[NSNumber numberWithFloat:1.];
basicScale.autoreverses=YES;
basicScale.duration=DURATION/2;
basicScale.fillMode=kCAFillModeForwards;
basicScale.removedOnCompletion=NO;
basicScale.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[label.layer addAnimation:basicScale forKey:@"s"];
CABasicAnimation *basicOpa=[CABasicAnimation animationWithKeyPath:@"opacity"];
basicOpa.fromValue=[NSNumber numberWithFloat:0.3];
basicOpa.toValue=[NSNumber numberWithFloat:1.];
basicOpa.autoreverses=YES;
basicOpa.duration=DURATION/2;
basicOpa.fillMode=kCAFillModeForwards;
basicOpa.removedOnCompletion=NO;
basicOpa.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[label.layer addAnimation:basicOpa forKey:@"o"];
UIBezierPath *path=[UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(label.frame.origin.x+thstrwidth/2, label.frame.origin.y+FONTHEIGHT/2)];
switch (i) {
case 0:
{
if ([temp count]==1||[temp count]==3) {
//
[path addLineToPoint:CGPointMake(label.frame.origin.x+thstrwidth/2, FONTHEIGHT/2)];
}else if([temp count]==2){
//
[path addCurveToPoint:CGPointMake(label.frame.origin.x+thstrwidth/2, FONTHEIGHT/2) controlPoint1:CGPointMake(label.frame.origin.x+thstrwidth/2, label.frame.origin.y+FONTHEIGHT/2) controlPoint2:CGPointMake(0, self.frame.size.height/2)];
}
}
break;
case 1:
{
if ([temp count]==3) {
//i==1
[path addCurveToPoint:CGPointMake(label.frame.origin.x+thstrwidth/2, FONTHEIGHT/2) controlPoint1:CGPointMake(label.frame.origin.x+thstrwidth/2, label.frame.origin.y+FONTHEIGHT/2) controlPoint2:CGPointMake(0, self.frame.size.height/2)];
}else if([temp count]==2){
//
[path addCurveToPoint:CGPointMake(label.frame.origin.x+thstrwidth/2, FONTHEIGHT/2) controlPoint1:CGPointMake(label.frame.origin.x+thstrwidth/2, label.frame.origin.y+FONTHEIGHT/2) controlPoint2:CGPointMake(self.frame.size.width, self.frame.size.height/2)];
}
}
break;
case 2:
[path addCurveToPoint:CGPointMake(label.frame.origin.x+thstrwidth/2, FONTHEIGHT/2) controlPoint1:CGPointMake(label.frame.origin.x+thstrwidth/2, label.frame.origin.y+FONTHEIGHT/2) controlPoint2:CGPointMake(self.frame.size.width, self.frame.size.height/2)];
break;
}
CAKeyframeAnimation *keyPosi=[CAKeyframeAnimation animationWithKeyPath:@"position"];
keyPosi.path=path.CGPath;
keyPosi.fillMode=kCAFillModeForwards;
keyPosi.removedOnCompletion=NO;
keyPosi.duration=DURATION;
keyPosi.delegate=self;
[keyPosi setValue:label forKeyPath:@"itslayer"];
keyPosi.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[label.layer addAnimation:keyPosi forKey:@"x"];
}
return butAry;
}
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
if (flag) {
UIView *vie=[anim valueForKeyPath:@"itslayer"];
[vie removeFromSuperview];
}
}
- (void)animationDidStart:(CAAnimation *)anim{
UIView *vie=[anim valueForKeyPath:@"itslayer"];
NSNumber *nu=[vie valueForKeyPath:@"timeoffset"];
if (nu!=nil) {
vie.layer.timeOffset=nu.floatValue;
}
}
-(void)reloadData:(NSArray *)ary{
if (dataARy!=nil) {
[dataARy release];
}
dataARy=ary;
[dataARy retain];
//
for (int i=0; i<DURATION/FIREINTERVAL; i++) {
NSArray *buttonaRY=[self bubbleUp];
for (UIView *vie in buttonaRY) {
[vie setValue:[NSNumber numberWithFloat:(i+1)*FIREINTERVAL] forKeyPath:@"timeoffset"];
}
}
NSTimer *tim=[NSTimer scheduledTimerWithTimeInterval:FIREINTERVAL target:self selector:@selector(bubbleUp) userInfo:nil repeats:YES];
[tim fire];
}
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
for (UIView *vie in self.subviews) {
if (CGRectContainsPoint(((CALayer *)vie.layer.presentationLayer).frame, point)) {
return vie;
}
}
return nil;
}
@end
@implementation NSArray(Modulo)
- (id)objectAtModuloIndex:(NSUInteger)index{
return [self objectAtIndex:index%[self count]];
}
@end
@implementation BubbleV
@synthesize delegate;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[delegate performSelector:@selector(touchDown:) withObject:self];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *tou= [touches anyObject];
if (CGRectContainsPoint([(CALayer *)[self.layer presentationLayer] frame], [tou locationInView:self.superview])) {
[delegate performSelector:@selector(touchUpInside:) withObject:self];
}else{
[delegate performSelector:@selector(touchOut:) withObject:self];
}
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *tou= [touches anyObject];
if (CGRectContainsPoint([(CALayer *)[self.layer presentationLayer] frame], [tou locationInView:self.superview])) {
[delegate performSelector:@selector(touchUpInside:) withObject:self];
}else{
[delegate performSelector:@selector(touchOut:) withObject:self];
}
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/DynamicLabel/CloudView.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 2,487 |
```objective-c
//
// ZYQSphereView.h
// SphereViewSample
//
// Created by Zhao Yiqi on 13-12-8.
//
#import "PFAxisDirection.h"
@interface ZYQSphereView : UIView {
NSMutableDictionary *pointMap;
CGPoint originalLocationInView;
CGPoint previousLocationInView;
PFAxisDirection lastXAxisDirection;
PFAxisDirection lastYAxisDirection;
CGRect originalSphereViewBounds;
}
@property(nonatomic,assign)BOOL isPanTimerStart;
@property(nonatomic,getter = isTimerStart,readonly)BOOL isTimerStart;
- (void)setItems:(NSArray *)items;
-(void)timerStart;
-(void)timerStop;
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/SphereView/SphereView/ZYQSphereView.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 148 |
```objective-c
//This file is part of SphereView.
//
//SphereView is free software: you can redistribute it and/or modify
//(at your option) any later version.
//
//SphereView is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//
//along with SphereView. If not, see <path_to_url
static PFMatrix PFMatrixTransform3DMakeFromPFPoint(PFPoint point) {
CGFloat pointRef[1][4] = {{point.x, point.y, point.z, 1}};
PFMatrix matrix = PFMatrixMakeFromArray(1, 4, *pointRef);
return matrix;
}
static PFMatrix PFMatrixTransform3DMakeTranslation(PFPoint point) {
CGFloat T[4][4] = {
{1, 0, 0, 0},
{0, 1, 0, 0},
{0, 0, 1, 0},
{point.x, point.y, point.z, 1}
};
PFMatrix matrix = PFMatrixMakeFromArray(4, 4, *T);
return matrix;
}
static PFMatrix PFMatrixTransform3DMakeXRotation(PFRadian angle) {
CGFloat c = cos(PFRadianMake(angle));
CGFloat s = sin(PFRadianMake(angle));
CGFloat T[4][4] = {
{1, 0, 0, 0},
{0, c, s, 0},
{0, -s, c, 0},
{0, 0, 0, 1}
};
PFMatrix matrix = PFMatrixMakeFromArray(4, 4, *T);
return matrix;
}
static PFMatrix PFMatrixTransform3DMakeXRotationOnPoint(PFPoint point, PFRadian angle) {
PFMatrix T = PFMatrixTransform3DMakeTranslation(PFPointMake(-point.x, -point.y, -point.z));
PFMatrix R = PFMatrixTransform3DMakeXRotation(angle);
PFMatrix T1 = PFMatrixTransform3DMakeTranslation(point);
return PFMatrixMultiply(PFMatrixMultiply(T, R), T1);
}
static PFMatrix PFMatrixTransform3DMakeYRotation(PFRadian angle) {
CGFloat c = cos(PFRadianMake(angle));
CGFloat s = sin(PFRadianMake(angle));
CGFloat T[4][4] = {
{c, 0, -s, 0},
{0, 1, 0, 0},
{s, 0, c, 0},
{0, 0, 0, 1}
};
PFMatrix matrix = PFMatrixMakeFromArray(4, 4, *T);
return matrix;
}
static PFMatrix PFMatrixTransform3DMakeYRotationOnPoint(PFPoint point, PFRadian angle) {
PFMatrix T = PFMatrixTransform3DMakeTranslation(PFPointMake(-point.x, -point.y, -point.z));
PFMatrix R = PFMatrixTransform3DMakeYRotation(angle);
PFMatrix T1 = PFMatrixTransform3DMakeTranslation(point);
return PFMatrixMultiply(PFMatrixMultiply(T, R), T1);
}
static PFMatrix PFMatrixTransform3DMakeZRotation(PFRadian angle) {
CGFloat c = cos(PFRadianMake(angle));
CGFloat s = sin(PFRadianMake(angle));
CGFloat T[4][4] = {
{c, s, 0, 0},
{-s, c, 0, 0},
{0, 0, 1, 0},
{0, 0, 0, 1}
};
PFMatrix matrix = PFMatrixMakeFromArray(4, 4, *T);
return matrix;
}
static PFMatrix PFMatrixTransform3DMakeZRotationOnPoint(PFPoint point, PFRadian angle) {
PFMatrix T = PFMatrixTransform3DMakeTranslation(PFPointMake(-point.x, -point.y, -point.z));
PFMatrix R = PFMatrixTransform3DMakeZRotation(angle);
PFMatrix T1 = PFMatrixTransform3DMakeTranslation(point);
return PFMatrixMultiply(PFMatrixMultiply(T, R), T1);
}
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/SphereView/SphereView/PFMatrixTransform.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 957 |
```objective-c
//This file is part of SphereView.
//
//SphereView is free software: you can redistribute it and/or modify
//(at your option) any later version.
//
//SphereView is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//
//along with SphereView. If not, see <path_to_url
#import "PFMatrix.h"
struct PFPoint {
CGFloat x;
CGFloat y;
CGFloat z;
};
typedef struct PFPoint PFPoint;
static PFPoint PFPointMake(CGFloat x, CGFloat y, CGFloat z) {
PFPoint p;
p.x = x;
p.y = y;
p.z = z;
return p;
}
static PFPoint PFPointMakeFromMatrix(PFMatrix matrix) {
return PFPointMake(matrix.data[0][0], matrix.data[0][1], matrix.data[0][2]);
}
static NSString *NSStringFromPFPoint(PFPoint point) {
NSString *str = [NSString stringWithFormat:@"(%f,%f,%f)", point.x, point.y, point.z];
return str;
}
#pragma mark -
#pragma mark CGPoint methods
static CGPoint CGPointMakeNormalizedPoint(CGPoint point, CGFloat distance) {
CGPoint nPoint = CGPointMake(point.x * 1/distance, point.y * 1/distance);
return nPoint;
}
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/SphereView/SphereView/PFPoint.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 296 |
```objective-c
//
// YFShineLabelViewController.m
// BigShow1949
//
// Created by zhht01 on 16/3/22.
//
#import "YFShineLabelViewController.h"
#import "RQShineLabel.h"
@interface YFShineLabelViewController ()
@property (strong, nonatomic) RQShineLabel *shineLabel;
@property (strong, nonatomic) NSArray *textArray;
@property (assign, nonatomic) NSUInteger textIndex;
@property (strong, nonatomic) UIImageView *wallpaper1;
@property (strong, nonatomic) UIImageView *wallpaper2;
@end
@implementation YFShineLabelViewController
- (void)viewDidLoad
{
[super viewDidLoad];
_textArray = @[
@"For something this complicated, its really hard to design products by focus groups. A lot of times, people dont know what they want until you show it to them.",
@"Were just enthusiastic about what we do.",
@"We made the buttons on the screen look so good youll want to lick them."
];
_textIndex = 0;
self.wallpaper1 = ({
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"wallpaper1"]];
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.frame = self.view.bounds;
imageView;
});
[self.view addSubview:self.wallpaper1];
self.wallpaper2 = ({
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"wallpaper2"]];
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.frame = self.view.bounds;
imageView.alpha = 0;
imageView;
});
[self.view addSubview:self.wallpaper2];
self.shineLabel = ({
RQShineLabel *label = [[RQShineLabel alloc] initWithFrame:CGRectMake(16, 16, 320 - 32, CGRectGetHeight(self.view.bounds) - 16)];
label.numberOfLines = 0;
label.text = [self.textArray objectAtIndex:self.textIndex];
label.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:24.0];
label.backgroundColor = [UIColor clearColor];
[label sizeToFit];
label.center = self.view.center;
label;
});
[self.view addSubview:self.shineLabel];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.shineLabel shine];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event];
if (self.shineLabel.isVisible) {
[self.shineLabel fadeOutWithCompletion:^{
[self changeText];
[UIView animateWithDuration:2.5 animations:^{
if (self.wallpaper1.alpha > 0.1) {
self.wallpaper1.alpha = 0;
self.wallpaper2.alpha = 1;
}
else {
self.wallpaper1.alpha = 1;
self.wallpaper2.alpha = 0;
}
}];
[self.shineLabel shine];
}];
}
else {
[self.shineLabel shine];
}
}
- (void)changeText
{
self.shineLabel.text = self.textArray[(++self.textIndex) % self.textArray.count];
}
-(UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/ShineLabel/YFShineLabelViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 720 |
```objective-c
//
// YFShineLabelViewController.h
// BigShow1949
//
// Created by zhht01 on 16/3/22.
//
#import <UIKit/UIKit.h>
@interface YFShineLabelViewController : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/ShineLabel/YFShineLabelViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 54 |
```objective-c
//
// ZYQSphereView.m
// SphereViewSample
//
// Created by Zhao Yiqi on 13-12-8.
//
#import "ZYQSphereView.h"
#import "PFGoldenSectionSpiral.h"
#import <QuartzCore/QuartzCore.h>
@interface ZYQSphereView(Private)
- (CGFloat)coordinateForNormalizedValue:(CGFloat)normalizedValue withinRangeOffset:(CGFloat)rangeOffset;
- (void)rotateSphereByAngle:(CGFloat)angle fromPoint:(CGPoint)fromPoint toPoint:(CGPoint)toPoint;
- (void)layoutViews;
- (void)layoutView:(UIView *)view withPoint:(PFPoint)point;
@end
@interface ZYQSphereView (){
float intervalX;
float intervalY;
}
@property(nonatomic,strong)NSTimer *timer;
@end
@implementation ZYQSphereView
-(BOOL)isTimerStart{
return [_timer isValid];
}
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
panRecognizer.minimumNumberOfTouches = 1;
[self addGestureRecognizer:panRecognizer];
[panRecognizer release];
UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchGesture:)];
[self addGestureRecognizer:pinchRecognizer];
[pinchRecognizer release];
UIRotationGestureRecognizer *rotationRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(handleRotationGesture:)];
[self addGestureRecognizer:rotationRecognizer];
[rotationRecognizer release];
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
tapRecognizer.numberOfTapsRequired = 1;
[self addGestureRecognizer:tapRecognizer];
[tapRecognizer release];
intervalX=1;
}
return self;
}
-(void)changeView{
CGPoint normalPoint=self.frame.origin;
CGPoint movePoint=CGPointMake(self.frame.origin.x+intervalX, self.frame.origin.y+intervalY);
[self rotateSphereByAngle:1 fromPoint:normalPoint toPoint:movePoint];
}
-(void)timerStart{
if (_timer.isValid) {
[_timer invalidate];
}
self.timer=[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(changeView) userInfo:nil repeats:YES];
}
-(void)timerStop{
if (_timer.isValid) {
[_timer invalidate];
}
}
- (void)setItems:(NSArray *)items {
[pointMap release];
pointMap = [[NSMutableDictionary alloc] init];
NSArray *spherePoints = [PFGoldenSectionSpiral sphere:items.count];
for (int i=0; i<items.count; i++) {
PFPoint point;
NSValue *pointRep = [spherePoints objectAtIndex:i];
[pointRep getValue:&point];
UIView *view = [items objectAtIndex:i];
view.tag = i;
[self layoutView:view withPoint:point];
[self addSubview:view];
[pointMap setObject:pointRep forKey:[NSNumber numberWithInt:i]];
}
[self rotateSphereByAngle:1 fromPoint:CGPointMake(0, 0) toPoint:CGPointMake(0, 1)];
}
- (void)setFrame:(CGRect)pFrame {
[super setFrame:pFrame];
originalSphereViewBounds = self.bounds;
}
#pragma mark -
#pragma mark UIGestureRecognizer methods
- (void)handlePanGesture:(UIPanGestureRecognizer *)panRecognizer {
switch (panRecognizer.state) {
case UIGestureRecognizerStateBegan:
originalLocationInView = [panRecognizer locationInView:self];
previousLocationInView = originalLocationInView;
break;
case UIGestureRecognizerStateChanged: {
CGPoint touchPoint = [panRecognizer locationInView:self];
CGPoint normalizedTouchPoint = CGPointMakeNormalizedPoint(touchPoint, self.frame.size.width);
CGPoint normalizedPreviousTouchPoint = CGPointMakeNormalizedPoint(previousLocationInView, self.frame.size.width);
CGPoint normalizedOriginalTouchPoint = CGPointMakeNormalizedPoint(originalLocationInView, self.frame.size.width);
// Touch direction handling
PFAxisDirection xAxisDirection = PFDirectionMakeXAxisSensitive(normalizedPreviousTouchPoint, normalizedTouchPoint);
if (xAxisDirection != lastXAxisDirection && xAxisDirection != PFAxisDirectionNone) {
lastXAxisDirection = xAxisDirection;
originalLocationInView = CGPointMake(touchPoint.x, previousLocationInView.y);
}
PFAxisDirection yAxisDirection = PFDirectionMakeYAxisSensitive(normalizedPreviousTouchPoint, normalizedTouchPoint);
if (yAxisDirection != lastYAxisDirection && yAxisDirection != PFAxisDirectionNone) {
lastYAxisDirection = yAxisDirection;
originalLocationInView = CGPointMake(previousLocationInView.x, touchPoint.y);
}
previousLocationInView = touchPoint;
intervalX=normalizedTouchPoint.x<normalizedOriginalTouchPoint.x?-1:1;
intervalY=normalizedTouchPoint.y<normalizedOriginalTouchPoint.y?-1:1;
// Sphere rotation
[self rotateSphereByAngle:1 fromPoint:normalizedOriginalTouchPoint toPoint:normalizedTouchPoint];
}
break;
default:
break;
}
if (_isPanTimerStart) {
[self timerStart];
}
}
- (void)handlePinchGesture:(UIPinchGestureRecognizer *)pinchRecognizer {
static CGRect InitialSphereViewBounds;
UIView *view = pinchRecognizer.view;
if (pinchRecognizer.state == UIGestureRecognizerStateBegan){
InitialSphereViewBounds = view.bounds;
}
CGFloat factor = pinchRecognizer.scale;
CGAffineTransform scaleTransform = CGAffineTransformScale(CGAffineTransformIdentity, factor, factor);
CGRect sphereFrame = CGRectApplyAffineTransform(InitialSphereViewBounds, scaleTransform);
CGRect screenFrame = [UIScreen mainScreen].bounds;
if ((sphereFrame.size.width > screenFrame.size.width
&& sphereFrame.size.height > screenFrame.size.height)
|| (sphereFrame.size.width < originalSphereViewBounds.size.width
&& sphereFrame.size.height < originalSphereViewBounds.size.height)) {
return;
}
view.bounds = sphereFrame;
[self layoutViews];
}
- (void)handleRotationGesture:(UIRotationGestureRecognizer *)rotationRecognizer {
static CGFloat LastSphereRotationAngle;
if (rotationRecognizer.state == UIGestureRecognizerStateEnded) {
LastSphereRotationAngle = 0;
return;
}
PFAxisDirection rotationDirection;
CGFloat rotation = rotationRecognizer.rotation;
if (rotation > LastSphereRotationAngle) {
rotationDirection = PFAxisDirectionPositive;
} else if (rotation < LastSphereRotationAngle) {
rotationDirection = PFAxisDirectionNegative;
}
rotation = fabs(rotation) * rotationDirection;
NSArray *subviews = self.subviews;
for (int i=0; i<subviews.count; i++) {
UIView *view = [subviews objectAtIndex:i];
NSNumber *key = [NSNumber numberWithInt:i];
PFPoint point;
NSValue *pointRep = [pointMap objectForKey:key];
[pointRep getValue:&point];
PFPoint aroundPoint = PFPointMake(0, 0, 0);
PFMatrix coordinate = PFMatrixTransform3DMakeFromPFPoint(point);
PFMatrix transform = PFMatrixTransform3DMakeZRotationOnPoint(aroundPoint, rotation);
point = PFPointMakeFromMatrix(PFMatrixMultiply(coordinate, transform));
[pointMap setObject:[NSValue value:&point withObjCType:@encode(PFPoint)] forKey:key];
[self layoutView:view withPoint:point];
}
LastSphereRotationAngle = rotationRecognizer.rotation;
}
- (void)handleTapGesture:(UITapGestureRecognizer *)tapRecognizer {
if ([self isTimerStart]) {
[self timerStop];
}
else{
[self timerStart];
}
}
#pragma mark -
#pragma mark Animation methods
- (void)rotateSphereByAngle:(CGFloat)angle fromPoint:(CGPoint)fromPoint toPoint:(CGPoint)toPoint {
NSArray *subviews = self.subviews;
for (int i=0; i<subviews.count; i++) {
UIView *view = [subviews objectAtIndex:i];
NSNumber *key = [NSNumber numberWithInt:i];
PFPoint point;
NSValue *pointRep = [pointMap objectForKey:key];
[pointRep getValue:&point];
PFPoint aroundPoint = PFPointMake(0, 0, 0);
PFMatrix coordinate = PFMatrixTransform3DMakeFromPFPoint(point);
PFMatrix transform = PFMatrixMakeIdentity(4,4);
PFAxisDirection xAxisDirection = PFDirectionMakeXAxis(fromPoint, toPoint);
if (xAxisDirection != PFAxisDirectionNone) {
transform = PFMatrixMultiply(transform, PFMatrixTransform3DMakeYRotationOnPoint(aroundPoint,xAxisDirection * -angle));
}
PFAxisDirection yAxisDirection = PFDirectionMakeYAxis(fromPoint, toPoint);
if (yAxisDirection != PFAxisDirectionNone) {
transform = PFMatrixMultiply(transform, PFMatrixTransform3DMakeXRotationOnPoint(aroundPoint,yAxisDirection * angle));
}
point = PFPointMakeFromMatrix(PFMatrixMultiply(coordinate, transform));
[pointMap setObject:[NSValue value:&point withObjCType:@encode(PFPoint)] forKey:key];
[self layoutView:view withPoint:point];
}
}
- (CGFloat)coordinateForNormalizedValue:(CGFloat)normalizedValue withinRangeOffset:(CGFloat)rangeOffset {
CGFloat half = rangeOffset / 2.f;
CGFloat coordinate = fabs(normalizedValue) * half;
if (normalizedValue > 0) {
coordinate += half;
} else {
coordinate = half - coordinate;
}
return coordinate;
}
- (void)layoutView:(UIView *)view withPoint:(PFPoint)point {
CGFloat viewSize = view.frame.size.width;
CGFloat width = self.frame.size.width - viewSize*2;
CGFloat x = [self coordinateForNormalizedValue:point.x withinRangeOffset:width];
CGFloat y = [self coordinateForNormalizedValue:point.y withinRangeOffset:width];
view.center = CGPointMake(x + viewSize, y + viewSize);
CGFloat z = [self coordinateForNormalizedValue:point.z withinRangeOffset:1];
view.transform = CGAffineTransformScale(CGAffineTransformIdentity, z, z);
view.layer.zPosition = z;
}
- (void)layoutViews {
NSArray *subviews = self.subviews;
for (int i=0; i<subviews.count; i++) {
UIView *view = [subviews objectAtIndex:i];
NSNumber *key = [NSNumber numberWithInt:i];
PFPoint point;
NSValue *pointRep = [pointMap objectForKey:key];
[pointRep getValue:&point];
[self layoutView:view withPoint:point];
}
}
- (void)dealloc {
[pointMap release];
if ([_timer isValid]) {
[_timer invalidate];
}
[_timer release];
[super dealloc];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/SphereView/SphereView/ZYQSphereView.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 2,453 |
```objective-c
//
// TSTextShineView.h
// TextShine
//
// Created by Genki on 5/7/14.
//
#import <UIKit/UIKit.h>
@interface RQShineLabel: UILabel
/**
* Fade in text animation duration. Defaults to 2.5.
*/
@property (assign, nonatomic, readwrite) CFTimeInterval shineDuration;
/**
* Fade out duration. Defaults to 2.5.
*/
@property (assign, nonatomic, readwrite) CFTimeInterval fadeoutDuration;
/**
* Auto start the animation. Defaults to NO.
*/
@property (assign, nonatomic, readwrite, getter = isAutoStart) BOOL autoStart;
/**
* Check if the animation is finished
*/
@property (assign, nonatomic, readonly, getter = isShining) BOOL shining;
/**
* Check if visible
*/
@property (assign, nonatomic, readonly, getter = isVisible) BOOL visible;
/**
* Start the animation
*/
- (void)shine;
- (void)shineWithCompletion:(void (^)())completion;
- (void)fadeOut;
- (void)fadeOutWithCompletion:(void (^)())completion;
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/ShineLabel/RQShineLabel.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 243 |
```objective-c
//
// TSTextShineView.m
// TextShine
//
// Created by Genki on 5/7/14.
//
#import "RQShineLabel.h"
@interface RQShineLabel()
@property (strong, nonatomic) NSMutableAttributedString *attributedString;
@property (nonatomic, strong) NSMutableArray *characterAnimationDurations;
@property (nonatomic, strong) NSMutableArray *characterAnimationDelays;
@property (strong, nonatomic) CADisplayLink *displaylink;
@property (assign, nonatomic) CFTimeInterval beginTime;
@property (assign, nonatomic) CFTimeInterval endTime;
@property (assign, nonatomic, getter = isFadedOut) BOOL fadedOut;
@property (nonatomic, copy) void (^completion)();
@end
@implementation RQShineLabel
- (instancetype)init
{
self = [super init];
if (!self) {
return nil;
}
[self commonInit];
return self;
}
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (!self) {
return nil;
}
[self commonInit];
return self;
}
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (!self) {
return nil;
}
[self commonInit];
[self setText:self.text];
return self;
}
- (void)commonInit
{
// Defaults
_shineDuration = 2.5;
_fadeoutDuration = 2.5;
_autoStart = NO;
_fadedOut = YES;
self.textColor = [UIColor whiteColor];
_characterAnimationDurations = [NSMutableArray array];
_characterAnimationDelays = [NSMutableArray array];
_displaylink = [CADisplayLink displayLinkWithTarget:self selector:@selector(updateAttributedString)];
_displaylink.paused = YES;
[_displaylink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
}
- (void)didMoveToWindow
{
if (nil != self.window && self.autoStart) {
[self shine];
}
}
- (void)setText:(NSString *)text
{
if (text) {
self.attributedText = [[NSAttributedString alloc] initWithString:text];
}else {
self.attributedText = [[NSAttributedString alloc] initWithString:@"The text is nil vv2vb"];
}
}
-(void)setAttributedText:(NSAttributedString *)attributedText
{
self.attributedString = [self initialAttributedStringFromAttributedString:attributedText];
[super setAttributedText:self.attributedString];
for (NSUInteger i = 0; i < attributedText.length; i++) {
self.characterAnimationDelays[i] = @(arc4random_uniform(self.shineDuration / 2 * 100) / 100.0);
CGFloat remain = self.shineDuration - [self.characterAnimationDelays[i] floatValue];
self.characterAnimationDurations[i] = @(arc4random_uniform(remain * 100) / 100.0);
}
}
- (void)shine
{
[self shineWithCompletion:NULL];
}
- (void)shineWithCompletion:(void (^)())completion
{
if (!self.isShining && self.isFadedOut) {
self.completion = completion;
self.fadedOut = NO;
[self startAnimationWithDuration:self.shineDuration];
}
}
- (void)fadeOut
{
[self fadeOutWithCompletion:NULL];
}
- (void)fadeOutWithCompletion:(void (^)())completion
{
if (!self.isShining && !self.isFadedOut) {
self.completion = completion;
self.fadedOut = YES;
[self startAnimationWithDuration:self.fadeoutDuration];
}
}
- (BOOL)isShining
{
return !self.displaylink.isPaused;
}
- (BOOL)isVisible
{
return NO == self.isFadedOut;
}
#pragma mark - Private methods
- (void)startAnimationWithDuration:(CFTimeInterval)duration
{
self.beginTime = CACurrentMediaTime();
self.endTime = self.beginTime + self.shineDuration;
self.displaylink.paused = NO;
}
- (void)updateAttributedString
{
CFTimeInterval now = CACurrentMediaTime();
for (NSUInteger i = 0; i < self.attributedString.length; i ++) {
if ([[NSCharacterSet whitespaceAndNewlineCharacterSet] characterIsMember:[self.attributedString.string characterAtIndex:i]]) {
continue;
}
[self.attributedString enumerateAttribute:NSForegroundColorAttributeName
inRange:NSMakeRange(i, 1)
options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired
usingBlock:^(id value, NSRange range, BOOL *stop) {
CGFloat currentAlpha = CGColorGetAlpha([(UIColor *)value CGColor]);
BOOL shouldUpdateAlpha = (self.isFadedOut && currentAlpha > 0) || (!self.isFadedOut && currentAlpha < 1) || (now - self.beginTime) >= [self.characterAnimationDelays[i] floatValue];
if (!shouldUpdateAlpha) {
return;
}
CGFloat percentage = (now - self.beginTime - [self.characterAnimationDelays[i] floatValue]) / ( [self.characterAnimationDurations[i] floatValue]);
if (self.isFadedOut) {
percentage = 1 - percentage;
}
UIColor *color = [self.textColor colorWithAlphaComponent:percentage];
[self.attributedString addAttribute:NSForegroundColorAttributeName value:color range:range];
}];
}
[super setAttributedText:self.attributedString];
if (now > self.endTime) {
self.displaylink.paused = YES;
if (self.completion) {
self.completion();
}
}
}
- (NSMutableAttributedString *)initialAttributedStringFromAttributedString:(NSAttributedString *)attributedString
{
NSMutableAttributedString *mutableAttributedString = [attributedString mutableCopy];
UIColor *color = [self.textColor colorWithAlphaComponent:0];
[mutableAttributedString addAttribute:NSForegroundColorAttributeName value:color range:NSMakeRange(0, mutableAttributedString.length)];
return mutableAttributedString;
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/ShineLabel/RQShineLabel.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 1,306 |
```objective-c
//
// YFRatingBar.m
// BigShow1949
//
// Created by zhht01 on 16/3/24.
//
#import "YFRatingBar.h"
#import "YFStar.h"
#define defaultStarCount 5
@interface YFRatingBar()
@property (nonatomic, strong) YFStar *star;
//@property (nonatomic, assign) CGFloat *starWH;
@end
@implementation YFRatingBar
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.backgroundColor = [UIColor whiteColor];
_miniSelectNumber = 1;
_starTotalNumber = defaultStarCount;
_starSelectNumber = _starTotalNumber;
self.enable = YES;
self.scrollSelectEnable = YES;
// bt_star_a bt_star_b
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
[self addGestureRecognizer:tap];
[self addGestureRecognizer:pan];
// :5
[self makeStarWithCount:self.starTotalNumber];
}
return self;
}
- (void)makeStarWithCount:(NSInteger)count {
NSLog(@"subviews = %@", self.subviews);
if (self.subviews.count) { //
for (YFStar *star in self.subviews) {
[star removeFromSuperview];
}
}
CGFloat starWH = self.frame.size.height; // star YFRatingBar
for(int i = 0; i < count; i++) {
YFStar *star = [[YFStar alloc] initWithFrame:CGRectMake(starWH * i, 0, starWH, starWH)];
self.star = star;
[self addSubview:star];
}
}
-(void)setViewColor:(UIColor *)backgroundColor{
if(_viewColor!=backgroundColor){
self.backgroundColor = backgroundColor;
}
}
-(void)tap:(UITapGestureRecognizer *)gesture{
if(self.enable){
CGPoint point = [gesture locationInView:self];
NSInteger count = (int)(point.x/self.frame.size.height) + 1;
count = count < self.miniSelectNumber ? self.miniSelectNumber : count;
self.starSelectNumber = count > self.starTotalNumber ? self.starTotalNumber : count;
}
}
-(void)pan:(UIPanGestureRecognizer *)gesture{
if(self.enable && self.scrollSelectEnable){
CGPoint point = [gesture locationInView:self];
NSInteger count = (int)(point.x/self.frame.size.height) + 1;
count = count < self.miniSelectNumber ? self.miniSelectNumber : count; //
if(count>=0 && count<=self.starTotalNumber && self.starSelectNumber!=count){
self.starSelectNumber = count;
}
}
}
- (void)setStarSelectNumber:(NSInteger)starSelectNumber {
_starSelectNumber = starSelectNumber;
//
if (starSelectNumber < self.miniSelectNumber) {
return;
}
// star
for (NSUInteger i = 0; i < self.subviews.count; i++) { // count 4 5
YFStar *star = self.subviews[i];
star.select = i < starSelectNumber ? YES : NO;
}
//
_scale = starSelectNumber;
}
- (void)setStarTotalNumber:(NSInteger)starTotalNumber {
if (_starTotalNumber != starTotalNumber) {
_starTotalNumber = starTotalNumber;
//
[self makeStarWithCount:starTotalNumber];
// // Q:,
// self.starSelectNumber = starTotalNumber;
// ,, 5
NSLog(@"starSelectNumber = %zd", self.starSelectNumber);
if (self.starSelectNumber != defaultStarCount) { // ,
[self setStarSelectNumber:self.starSelectNumber]; // ,
}else {
self.starSelectNumber = starTotalNumber;
}
}
}
//
//- (void)setMiniSelectNumber:(NSInteger)miniSelectNumber {
//
// _miniSelectNumber = miniSelectNumber;
//
//
// [self judgeStarValid];
//
//}
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/RatingBar/YFRatingBar.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 931 |
```objective-c
//
// YFRatingBar.h
// BigShow1949
//
// Created by zhht01 on 16/3/24.
//
#import <UIKit/UIKit.h>
@interface YFRatingBar : UIView
@property (nonatomic,assign) NSInteger starTotalNumber; // : 5
@property (nonatomic,assign) NSInteger starSelectNumber; // :
@property (nonatomic,assign) NSInteger miniSelectNumber; // : 1
@property (nonatomic,assign,readonly) NSInteger scale; //
/**
* (:)
*/
@property (nonatomic,strong) UIColor *viewColor;
/**
* (:)
*/
@property (nonatomic,assign) BOOL enable;
/**
* (:) (enable = YES)
*/
@property (nonatomic,assign) BOOL scrollSelectEnable;
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/RatingBar/YFRatingBar.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 161 |
```objective-c
//
// YFRatingBarViewController.h
// BigShow1949
//
// Created by zhht01 on 16/3/24.
//
#import <UIKit/UIKit.h>
@interface YFRatingBarViewController : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/RatingBar/YFRatingBarViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 52 |
```objective-c
//
// YFRatingBarViewController.m
// BigShow1949
//
// Created by zhht01 on 16/3/24.
//
#import "YFRatingBarViewController.h"
#import "YFRatingBar.h"
@interface YFRatingBarViewController ()
@property (nonatomic, strong) YFRatingBar *bar;
@end
@implementation YFRatingBarViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
YFRatingBar *bar = [[YFRatingBar alloc] initWithFrame:CGRectMake(50, 50, 260, 35)]; // 5
self.bar = bar;
bar.viewColor = [UIColor lightGrayColor];
bar.starSelectNumber = 4;
bar.miniSelectNumber = 3;
[self.view addSubview:bar];
bar.center = self.view.center;
// test
UIButton *btn = [[UIButton alloc] init];
btn.frame = CGRectMake(100, 100, 100, 100);
btn.backgroundColor = [UIColor redColor];
[self.view addSubview:btn];
[btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)btnClick:(UIButton *)btn {
NSLog(@"starTotalNumber = %zd, starSelectNumber = %zd, bar.scale = %zd", self.bar.starTotalNumber, self.bar.starSelectNumber, self.bar.scale);
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/RatingBar/YFRatingBarViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 306 |
```objective-c
//
// YFStar.h
// BigShow1949
//
// Created by zhht01 on 16/3/24.
//
#import <UIKit/UIKit.h>
@interface YFStar : UIView
@property (nonatomic, getter=isSelect) BOOL select;
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/RatingBar/YFStar.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 59 |
```objective-c
//
// YFLazyInViewController.m
// BigShow1949
//
// Created by zhht01 on 16/3/22.
//
#import "YFLazyInViewController.h"
#import "LazyFadeInView.h"
static NSString * const kStrayBirds = @"Stray birds of summer come to my window to sing and fly away. And yellow leaves of autumn, which have no songs, flutter and fall there with a sign. O Troupe of little vagrants of the world, leave your footprints in my words.";
static NSString * const kChinesePoem = @"";
@interface YFLazyInViewController ()
@property (strong, nonatomic) LazyFadeInView *fadeInView;
@property (assign, nonatomic) BOOL flag;
@end
@implementation YFLazyInViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor blackColor];
self.fadeInView = [[LazyFadeInView alloc] initWithFrame:CGRectMake(20, 120, 280, 200)];
// self.fadeInView.text = kStrayBirds;
[self.view addSubview:self.fadeInView];
}
- (IBAction)setTextBtnClicked:(id)sender
{
if (_flag)
{
self.fadeInView.text = kStrayBirds;
_flag = !_flag;
}
else
{
self.fadeInView.text = kChinesePoem;
_flag = !_flag;
}
}
- (IBAction)colorSwitched:(id)sender
{
if (((UISwitch *)sender).on == YES)
{
self.view.backgroundColor = [UIColor colorWithRed:0.24 green:0.48 blue:0.82 alpha:1];
}
else
{
self.view.backgroundColor = [UIColor blackColor];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/LazyFadeInView/YFLazyInViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 388 |
```objective-c
//
// YFLazyInViewController.h
// BigShow1949
//
// Created by zhht01 on 16/3/22.
//
#import <UIKit/UIKit.h>
@interface YFLazyInViewController : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/LazyFadeInView/YFLazyInViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 52 |
```objective-c
//
// YFStar.m
// BigShow1949
//
// Created by zhht01 on 16/3/24.
//
#import "YFStar.h"
#define kScale 0.6
@interface YFStar()
@property (nonatomic, strong) UIImageView *imgView;
@end
@implementation YFStar
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self makeView:frame];
}
return self;
}
- (void)makeView:(CGRect)frame {
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bt_star_b"]];
self.imgView = imgView;
[self addSubview:imgView];
CGFloat imgWH = frame.size.width;
imgView.frame = CGRectMake(0, 0, imgWH * kScale, imgWH * kScale);
imgView.center = CGPointMake(imgWH * 0.5, imgWH * 0.5);
}
- (void)setSelect:(BOOL)select {
NSString *imgName;
if (select) {
imgName = @"bt_star_b";
}else {
imgName = @"bt_star_a";
}
[self.imgView setImage:[UIImage imageNamed:imgName]];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/RatingBar/YFStar.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 275 |
```objective-c
//
// LazyFadeIn.h
// LazyFadeInView
//
// Created by Tu You on 14-4-21.
//
#import <Foundation/Foundation.h>
@protocol LazyFadeIn <NSObject>
//! @abstract The duration of the complete fading. Defaults to 1.0.
@property (assign, nonatomic, readwrite) CFTimeInterval duration;
//! @abstract The number of layers lazy loading. Defaults to 3.
@property (assign, nonatomic, readwrite) NSUInteger numberOfLayers;
//! @abstract The interval of layers fading. Defaults to 0.2
@property (assign, nonatomic, readwrite) CFTimeInterval interval;
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/LazyFadeInView/LazyFadeInView/LazyFadeIn.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 133 |
```objective-c
//
// LazyFadeInView.m
// LazyFadeInView
//
// Created by Tu You on 14-4-20.
//
#import "LazyFadeInView.h"
#import "LazyFadeInLayer.h"
#define __layer ((LazyFadeInLayer *)self.layer)
@implementation LazyFadeInView
+ (Class)layerClass
{
return [LazyFadeInLayer class];
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
self.backgroundColor = [UIColor clearColor];
self.contentScaleFactor = [[UIScreen mainScreen] scale];
}
return self;
}
- (void)setText:(NSString *)text
{
__layer.text = text;
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/LazyFadeInView/LazyFadeInView/LazyFadeInView.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 153 |
```objective-c
//
// LazyFadeInView.h
// LazyFadeInView
//
// Created by Tu You on 14-4-20.
//
#import <UIKit/UIKit.h>
@interface LazyFadeInView : UIView
@property (strong, nonatomic) NSString *text;
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/LazyFadeInView/LazyFadeInView/LazyFadeInView.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 56 |
```objective-c
//
// LazyFadeInLayer.h
// LazyFadeInView
//
// Created by Tu You on 14-4-20.
//
#import <QuartzCore/QuartzCore.h>
#import "LazyFadeIn.h"
@interface LazyFadeInLayer : CATextLayer <LazyFadeIn>
@property (strong, nonatomic) NSString *text;
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/LazyFadeInView/LazyFadeInView/LazyFadeInLayer.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 76 |
```objective-c
//
// LazyFadeInLayer.m
// LazyFadeInView
//
// Created by Tu You on 14-4-20.
//
#import "LazyFadeInLayer.h"
#import <CoreText/CoreText.h>
@interface LazyFadeInLayer ()
@property (strong, nonatomic) CADisplayLink *displayLink;
@property (strong, nonatomic) NSMutableArray *alphaArray;
@property (strong, nonatomic) NSMutableAttributedString *attributedString;
@property (strong, nonatomic) NSMutableArray *tmpArray;
@end
@implementation LazyFadeInLayer
@synthesize duration = _duration;
@synthesize numberOfLayers = _numberOfLayers;
@synthesize interval = _interval;
- (instancetype)init
{
self = [super init];
if (self)
{
_duration = 1.2f;
_numberOfLayers = 6;
_interval = 0.2;
_alphaArray = [NSMutableArray array];
_tmpArray = [NSMutableArray array];
_attributedString = [[NSMutableAttributedString alloc] init];
self.wrapped = YES;
}
return self;
}
- (void)setText:(NSString *)text
{
[_displayLink removeFromRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
if (!text)
{
_text = @" ";
}
else
{
_text = text;
}
_attributedString = [[NSMutableAttributedString alloc] initWithString:_text];
if (_text.length != 0)
{
[self setupAlphaArray];
_displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(frameUpdate:)];
[_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
}
}
- (void)frameUpdate:(id)sender
{
[self.attributedString removeAttribute:(NSString *)kCTForegroundColorAttributeName range:NSMakeRange(0, self.text.length)];
BOOL shouldRemoveTimer = YES;
for (int i = 0; i < self.text.length; ++i)
{
float alpha = [_alphaArray[i] floatValue];
alpha = alpha < 0.0 ? 0.0 : alpha;
alpha = alpha > 1.0 ? 1.0 : alpha;
if (alpha != 1.0)
{
shouldRemoveTimer = NO;
}
UIColor *letterColor = [UIColor colorWithWhite:1 alpha:alpha];
[self.attributedString addAttribute:(NSString *)kCTForegroundColorAttributeName
value:(id)letterColor.CGColor
range:NSMakeRange(i, 1)];
}
if (shouldRemoveTimer)
{
[_displayLink removeFromRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
_displayLink = nil;
}
CTFontRef helveticaBold = CTFontCreateWithName(CFSTR("HelveticaNeue-Light"), 20.0, NULL);
[self.attributedString addAttribute:(NSString *)kCTFontAttributeName
value:(__bridge id)helveticaBold
range:NSMakeRange(0, self.text.length)];
NSMutableArray *tAlpha = [NSMutableArray array];
for (int i = 0; i < _alphaArray.count; ++i)
{
float newAlpha = [_alphaArray[i] floatValue] + (1.0 / 40);
[tAlpha addObject:@(newAlpha)];
}
_alphaArray = tAlpha;
self.string = (id)self.attributedString;
}
- (void)setupAlphaArray
{
[_alphaArray removeAllObjects];
for (int i = 0; i < self.text.length; ++i)
{
[_alphaArray addObject:@(MAXFLOAT)];
}
[self randomAlphaArray];
}
- (void)randomAlphaArray
{
NSUInteger totalCount = self.text.length;
NSUInteger tTotalCount = totalCount;
[_tmpArray removeAllObjects];
for (int i = 0; i < _numberOfLayers - 1; ++i)
{
int k = arc4random() % tTotalCount;
[_tmpArray addObject:@(k)];
tTotalCount -= k;
}
[_tmpArray addObject:@(tTotalCount)];
for (id value in _tmpArray)
{
NSLog(@"%@", value);
}
for (int i = 0; i < _numberOfLayers; ++i)
{
int count = [_tmpArray[i] intValue];
CGFloat alpha = -(i * 0.25);
while (count)
{
int k = arc4random() % totalCount;
if ([_alphaArray[k] floatValue] > 0.0f)
{
_alphaArray[k] = @(alpha);
count--;
}
}
}
for (id value in _alphaArray)
{
NSLog(@"%@", value);
}
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/LazyFadeInView/LazyFadeInView/LazyFadeInLayer.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 1,029 |
```objective-c
//
// WWScrollTagsCloud.h
// ScrollTagsCloud
//
// Created by mac on 14-7-24.
//
@protocol WWTagsCloudViewDelegate <NSObject>
@optional
-(void)tagClickAtIndex:(NSInteger)tagIndex;
@end
#import <UIKit/UIKit.h>
@interface WWTagsCloudView : UIView
@property (strong, nonatomic) id<WWTagsCloudViewDelegate> delegate;
-(id)initWithFrame:(CGRect)frame andTags:(NSArray*)tags andTagColors:(NSArray*)tagColors andFonts:(NSArray*)fonts andParallaxRate:(CGFloat)parallaxRate andNumOfLine:(NSInteger)lineNum;
-(void)reloadAllTags;
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/TagsCloudView/WWTagsCloudView.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 142 |
```objective-c
//
// YFTagsCloudViewController.h
// BigShow1949
//
// Created by zhht01 on 16/3/22.
//
#import <UIKit/UIKit.h>
#import "WWTagsCloudView.h"
@interface YFTagsCloudViewController : UIViewController<WWTagsCloudViewDelegate>
- (IBAction)refreshBtnClick:(id)sender;
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/TagsCloudView/YFTagsCloudViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 77 |
```objective-c
//
// YFTagsCloudViewController.m
// BigShow1949
//
// Created by zhht01 on 16/3/22.
//
#import "YFTagsCloudViewController.h"
@interface YFTagsCloudViewController ()
@property (strong, nonatomic) WWTagsCloudView* tagCloud;
@property (strong, nonatomic) NSArray* tags;
@end
@implementation YFTagsCloudViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
_tags = @[@"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", @"", ];
NSArray* colors = @[[UIColor colorWithRed:0 green:0.63 blue:0.8 alpha:1], [UIColor colorWithRed:1 green:0.2 blue:0.31 alpha:1], [UIColor colorWithRed:0.53 green:0.78 blue:0 alpha:1], [UIColor colorWithRed:1 green:0.55 blue:0 alpha:1]];
NSArray* fonts = @[[UIFont systemFontOfSize:12], [UIFont systemFontOfSize:16], [UIFont systemFontOfSize:20]];
//
_tagCloud = [[WWTagsCloudView alloc] initWithFrame:CGRectMake(0, 0, 320, 200)
andTags:_tags
andTagColors:colors
andFonts:fonts
andParallaxRate:1.7
andNumOfLine:3];
_tagCloud.delegate = self;
[self.view addSubview:_tagCloud];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)tagClickAtIndex:(NSInteger)tagIndex
{
NSLog(@"%@",_tags[tagIndex]);
}
- (IBAction)refreshBtnClick:(id)sender {
[_tagCloud reloadAllTags];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/TagsCloudView/YFTagsCloudViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 425 |
```objective-c
//
// WWScrollTagsCloud.m
// SearchTest
//
// Created by mac on 14-7-24.
//
@interface WWScrollView : UIScrollView
@property (nonatomic) CGFloat parallaxRate;
@end
@implementation WWScrollView
//floatViewscrollviewViewlayoutSubviewsfloatViewscrollviewscrollviewlabelSDKscrollview
-(void)layoutSubviews
{
UIView* floatView = [self viewWithTag:100];
floatView.frame = CGRectMake(0, 0, self.contentSize.width * _parallaxRate, self.frame.size.height);
CGRect tempRect = floatView.frame;
tempRect.origin.x = -self.contentOffset.x * (_parallaxRate - 1);
floatView.frame = tempRect;
}
//scrollviewviewfloatViewuserInteractionEnabledNOfloatViewhitTestfloatView
-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
UIView* hitView = [super hitTest:point withEvent:event];
if ([hitView isMemberOfClass:[WWScrollView class]]) {
for (UIView* subView in [self viewWithTag:100].subviews) {
CGPoint subPoint = [self convertPoint:point toView:subView];
if ([subView hitTest:subPoint withEvent:event]) {
return subView;
}
}
}
return hitView;
}
@end
#import "WWTagsCloudView.h"
#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height
#define PADDING_X 20//
#define MARGIN_LEFT 20//
#define MARGIN_TOP 50//
#define LINE_HEIGHT 50//
@interface WWTagsCloudView ()
@property (strong, nonatomic) UIScrollView* scrollView;
@property (strong, nonatomic) UIView* floatView;
@property (strong, nonatomic) NSArray* tagArray;
@property (strong, nonatomic) NSArray* tagColorArray;
@property (strong, nonatomic) NSArray* fontArray;
@property (nonatomic) NSInteger lineNum;
@property (nonatomic) CGFloat parallaxRate;
@end
@implementation WWTagsCloudView
-(id)initWithFrame:(CGRect)frame andTags:(NSArray*)tags andTagColors:(NSArray*)tagColors andFonts:(NSArray*)fonts andParallaxRate:(CGFloat)parallaxRate andNumOfLine:(NSInteger)lineNum
{
//
self = [super initWithFrame:frame];
_tagArray = tags;
_tagColorArray = tagColors;
_fontArray = fonts;
_lineNum = lineNum;
_parallaxRate = parallaxRate < 1 ? 1 : parallaxRate;
_scrollView = [[WWScrollView alloc] initWithFrame:frame];
((WWScrollView*)_scrollView).parallaxRate = _parallaxRate;
_scrollView.pagingEnabled = YES;
_scrollView.showsHorizontalScrollIndicator = NO;
//X
[self addSubview:_scrollView];
//
_floatView = [[UIView alloc] init];
//scrollView
_floatView.userInteractionEnabled = NO;
_floatView.tag = 100;
[_scrollView addSubview:_floatView];
_scrollView.contentSize = CGSizeMake(SCREEN_WIDTH * [self createLbInContainer], 0);
return self;
}
-(void)reloadAllTags
{
for (UIView* subView in _scrollView.subviews) {
if ([subView isMemberOfClass:[UILabel class]]) {
[subView removeFromSuperview];
}
}
for (UIView* subView in _floatView.subviews) {
if ([subView isMemberOfClass:[UILabel class]]) {
[subView removeFromSuperview];
}
}
_scrollView.contentSize = CGSizeMake(SCREEN_WIDTH * [self createLbInContainer], 0);
}
-(void)tagClickAtIndex:(UITapGestureRecognizer*)gesture
{
[self.delegate tagClickAtIndex:gesture.view.tag];
}
-(NSInteger)createLbInContainer
{
//
NSInteger currentPageIndex = 0;
//
NSMutableArray* indexArray = [[NSMutableArray alloc] init];
for (int i = 0; i < _tagArray.count; i++) {
[indexArray addObject:[NSNumber numberWithInt:i]];
}
while (indexArray.count > 0) {
for (int i = 0; i < _lineNum; i++) {
//tagX
CGFloat currentX = arc4random() % (MARGIN_LEFT - PADDING_X + 1) + PADDING_X + SCREEN_WIDTH * currentPageIndex;
//label
BOOL isFloatLabel = arc4random() % 2;
while (indexArray.count > 0) {
NSInteger indexOfIndexArray = arc4random() % indexArray.count;
//
NSInteger tagIndex = [indexArray[indexOfIndexArray] intValue];
UILabel* label = [[UILabel alloc] init];
label.tag = tagIndex;
//
label.text = _tagArray[tagIndex];
//
label.textColor = _tagColorArray[arc4random() % _tagColorArray.count];
//
label.font = _fontArray[arc4random() % _fontArray.count];
//frame
label.frame = CGRectMake(currentX, MARGIN_TOP + i * LINE_HEIGHT, [self getLabelWidthWithLabel:label], label.font.lineHeight);
//
if (currentX + label.frame.size.width + PADDING_X > SCREEN_WIDTH * (currentPageIndex + 1)) {
break;
}
currentX += label.frame.size.width + PADDING_X;
//x,y
CGRect tempRect = label.frame;
tempRect.origin.y -= (label.font.lineHeight / 2);
if (isFloatLabel) {
tempRect.origin.x += currentPageIndex * SCREEN_WIDTH * (_parallaxRate - 1);
label.frame = tempRect;
[_floatView addSubview:label];
}
else{
label.frame = tempRect;
[_scrollView addSubview:label];
}
[indexArray removeObject:indexArray[indexOfIndexArray]];
//
label.userInteractionEnabled = YES;
UITapGestureRecognizer* tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tagClickAtIndex:)];
[label addGestureRecognizer:tapGesture];
isFloatLabel = !isFloatLabel;
}
}
currentPageIndex++;
}
return currentPageIndex;
}
//labellabel
-(CGFloat)getLabelWidthWithLabel:(UILabel*)label
{
NSDictionary *attribute = @{NSFontAttributeName: label.font};
CGSize retSize = [label.text boundingRectWithSize:CGSizeMake(MAXFLOAT, label.font.lineHeight)
options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attribute
context:nil].size;
return retSize.width;
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/02 - Label(标签)/TagsCloudView/WWTagsCloudView.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 1,414 |
```objective-c
//
// YFDesignPatternViewController.h
// BigShow1949
//
// Created by zhht01 on 16/3/30.
//
#import "BaseTableViewController.h"
@interface YFDesignPatternViewController : BaseTableViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/YFDesignPatternViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 55 |
```objective-c
//
// MVPLoginViewController.m
// BigShow1949
//
// Created by apple on 17/8/11.
//
#import "MVPLoginViewController.h"
#import "LoginViewProtocol.h"
#import "LoginPresenter.h"
@interface MVPLoginViewController ()<LoginViewProtocol>
@property (nonatomic,strong) LoginPresenter* presenter;
@end
@implementation MVPLoginViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
//
UIButton *redBtn = [[UIButton alloc] init];
redBtn.frame = CGRectMake(100, 100, 100, 100);
[redBtn setTitle:@" " forState:UIControlStateNormal];
[redBtn addTarget:self action:@selector(loginClick) forControlEvents:UIControlEventTouchUpInside];
redBtn.backgroundColor = [UIColor redColor];
[self.view addSubview:redBtn];
}
- (void)loginClick {
_presenter = [[LoginPresenter alloc ]init];
[_presenter attachView:self];
//()()
[_presenter loginWithName:@"18842693828" pwd:@"123456"];
}
- (void)onLoginResult:(NSString *)result{
NSLog(@" = %@",result);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
[_presenter detachView];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Login/MVPLoginViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 267 |
```objective-c
//
// YFDesignPatternViewController.m
// BigShow1949
//
// Created by zhht01 on 16/3/30.
//
#import "YFDesignPatternViewController.h"
@interface YFDesignPatternViewController ()
@end
@implementation YFDesignPatternViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setupDataArr:@[@[@"MVVM_coderyi",@"YiTableViewController"],
@[@"DataSource",@"MyDataSourceViewController"],
@[@"MVP",@"MVPLoginViewController"],
@[@"MVP2",@"MVPLogin2ViewController_UIStoryboard"],
@[@"MVP",@"MVPCounterViewController"],
@[@"MVP Home",@"MVPHomeViewController"],
@[@"Router",@"YFRouterViewController"],
@[@"VIPER",@"YFVIPERViewController"]]]; //
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/YFDesignPatternViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 177 |
```objective-c
//
// HttpUtils.h
// Dream_Architect_MVP_OC
//
// Created by Apple on 2017/2/7.
//
#import <Foundation/Foundation.h>
typedef void(^Callback) (NSString* result);
@interface HttpUtils : NSObject
+ (void)postWithName:(NSString*)name pwd:(NSString*)pwd callback:(Callback)callback;
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Login/HttpUtils.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 79 |
```objective-c
//
// LoginPresenter.h
// BigShow1949
//
// Created by apple on 17/8/11.
//
#import <Foundation/Foundation.h>
#import "LoginViewProtocol.h"
#import "LoginModel.h"
// P
//(MV)
@interface LoginPresenter : NSObject
//
- (void)loginWithName:(NSString*)name pwd:(NSString*)pwd;
- (void)attachView:(id<LoginViewProtocol>)loginView;
- (void)detachView;
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Login/LoginPresenter.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 103 |
```objective-c
//
// LoginViewProtocal.h
// BigShow1949
//
// Created by apple on 17/8/11.
//
#import <Foundation/Foundation.h>
//V
@protocol LoginViewProtocol <NSObject>
- (void)onLoginResult:(NSString*)result;
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Login/LoginViewProtocol.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 62 |
```objective-c
//
// LoginPresenter.m
// BigShow1949
//
// Created by apple on 17/8/11.
//
#import "LoginPresenter.h"
//P(MV)
//P:MV(OOP)
@interface LoginPresenter ()
@property (nonatomic,strong) LoginModel *loginModel;
@property (nonatomic,strong) id<LoginViewProtocol> loginView;
@end
@implementation LoginPresenter
- (instancetype)init{
self = [super init];
if (self) {
//M
_loginModel = [[LoginModel alloc]init];
}
return self;
}
//V
//
- (void)attachView:(id<LoginViewProtocol>)loginView{
_loginView = loginView;
}
//
- (void)detachView{
_loginView = nil;
}
//
- (void)loginWithName:(NSString*)name pwd:(NSString*)pwd{
[_loginModel loginWithName:name pwd:pwd callback:^(NSString *result) {
if (_loginView != nil) {
[_loginView onLoginResult:result];
}
}];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Login/LoginPresenter.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 228 |
```objective-c
//
// HttpUtils.m
// Dream_Architect_MVP_OC
//
// Created by Apple on 2017/2/7.
//
#import "HttpUtils.h"
@implementation HttpUtils
+ (void)postWithName:(NSString*)name pwd:(NSString*)pwd callback:(Callback)callback{
//
//(,)
//()
//
//:
NSURL *url = [NSURL URLWithString:@"path_to_url"];
//:
NSMutableURLRequest * request = [[NSMutableURLRequest alloc]initWithURL:url];
//:
request.HTTPMethod = @"POST";
NSString *params = [NSString stringWithFormat:@"mobile=%@&password=%@",name,pwd];
request.HTTPBody = [params dataUsingEncoding:NSUTF8StringEncoding];
//:
//
NSURLSession *session = [NSURLSession sharedSession];
//:
NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
//:
if (error!=nil) {
NSLog(@"");
}else{
NSLog(@"");
//
NSString *result = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
callback(result);
}
}];
// :
[task resume];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Login/HttpUtils.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 271 |
```objective-c
//
// MVPLoginViewController.h
// BigShow1949
//
// Created by apple on 17/8/11.
//
#import <UIKit/UIKit.h>
@interface MVPLoginViewController : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Login/MVPLoginViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 46 |
```objective-c
//
// LoginModel.m
// BigShow1949
//
// Created by apple on 17/8/11.
//
#import "LoginModel.h"
@implementation LoginModel
- (void)loginWithName:(NSString*)name pwd:(NSString*)pwd callback:(Callback)callback{
//
//:??
//()
[HttpUtils postWithName:name pwd:pwd callback:^(NSString *result) {
//json ,xml
//
//100
callback(result);//
}];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Login/LoginModel.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 109 |
```objective-c
//
// LoginModel.h
// BigShow1949
//
// Created by apple on 17/8/11.
//
#import <Foundation/Foundation.h>
#import "HttpUtils.h"
//M(,,,...)
@interface LoginModel : NSObject
//
- (void)loginWithName:(NSString*)name pwd:(NSString*)pwd callback:(Callback)callback;
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/MVP_Login/LoginModel.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 78 |
```objective-c
//
// YFRouterViewController.m
// BigShow1949
//
// Created by apple on 17/8/16.
//
#import "YFRouterViewController.h"
@interface YFRouterViewController ()
@end
@implementation YFRouterViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setupDataArr:@[@[@"EcoRouter",@"EcoMainViewController"],
@[@"JLRouters",@"JLRoutersTabbarController"]]];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/YFRouterViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 124 |
```objective-c
//
// YFRouterViewController.h
// BigShow1949
//
// Created by apple on 17/8/16.
//
#import "BaseTableViewController.h"
@interface YFRouterViewController : BaseTableViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/YFRouterViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 51 |
```html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "path_to_url">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="1504.76">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; line-height: 14.0px; font: 12.0px Courier; color: #000000; -webkit-text-stroke: #000000}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; line-height: 14.0px; font: 12.0px 'PingFang SC'; color: #000000; -webkit-text-stroke: #000000}
span.s1 {font-kerning: none}
span.s2 {font: 12.0px Courier; font-kerning: none}
span.Apple-tab-span {white-space:pre}
</style>
</head>
<body>
<p/>
<p/>
<p/>
<br/>
<br/>
<br/>
<br/>
<a href = "eco://moduleA/Root">1-A-</a>
<p/>
<p/>
<p/>
<a href = "eco://moduleB/Root?id=110&name=nimei&password=nidaye">2-B-</a>
<p/>
<p/>
<p/>
<a href = "eco://C?id=110&name=nimei&password=nidaye">3-</a>
</body>
</html>
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/EcoRouterDemo/router.html | html | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 393 |
```objective-c
//
// EcoBaseViewController.h
// BigShow1949
//
// Created by apple on 17/8/16.
//
#import <UIKit/UIKit.h>
@interface EcoBaseViewController : UIViewController
///Item
- (void)addLeftItem;
///Item
- (void)addRightItem;
@end
``` | /content/code_sandbox/BigShow1949/Classes/10 - DesignPattern(设计模式)/Router/EcoRouterDemo/EcoBaseViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 68 |
```objective-c
//
// EcoBaseViewController.m
// BigShow1949
//
// Created by apple on 17/8/16.
//
#import "EcoBaseViewController.h"
#import "UIViewController+Router.h"
@interface EcoBaseViewController ()
@property (nonatomic, strong) UITextView *resultTextView;
@end
@implementation EcoBaseViewController
#pragma mark - lifeCycle
- (void)viewDidLoad
{
[super viewDidLoad];
//UI
[self initUI];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - UI
- (void)initUI
{
self.view.backgroundColor = [UIColor whiteColor];
[self.view addSubview:self.resultTextView];
[self setNavBarItem];
}
- (UITextView *)resultTextView
{
if (!_resultTextView) {
NSInteger padding = 20;
NSInteger viewWith = self.view.frame.size.width;
NSInteger viewHeight = self.view.frame.size.height - 64;
_resultTextView = [[UITextView alloc] initWithFrame:CGRectMake(padding, padding + 64, viewWith - padding * 2, viewHeight - padding * 2)];
_resultTextView.layer.borderColor = [UIColor colorWithWhite:0.8 alpha:1].CGColor;
_resultTextView.layer.borderWidth = 1;
_resultTextView.editable = NO;
_resultTextView.contentInset = UIEdgeInsetsMake(-64, 0, 0, 0);
_resultTextView.font = [UIFont systemFontOfSize:14];
_resultTextView.textColor = [UIColor colorWithWhite:0.2 alpha:1];
_resultTextView.contentOffset = CGPointZero;
[self appendLog:self.paramDic.description];
}
return _resultTextView;
}
- (void)appendLog:(NSString *)log
{
NSString *currentLog = self.resultTextView.text;
if (currentLog.length) {
currentLog = [currentLog stringByAppendingString:[NSString stringWithFormat:@"\n----------\n%@", log]];
} else {
currentLog = log;
}
self.resultTextView.text = currentLog;
[self.resultTextView sizeThatFits:CGSizeMake(self.view.frame.size.width, CGFLOAT_MAX)];
}
///
- (void)setNavBarItem
{
[self addLeftItem];
[self addRightItem];
}
- (void)addLeftItem
{
UIBarButtonItem *cancelItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(actionCancel)];
self.navigationItem.leftBarButtonItem = cancelItem;
}
- (void)addRightItem
{
UIBarButtonItem *goItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(actionGo)];
self.navigationItem.rightBarButtonItem = goItem;
}
#pragma mark - Action
///
- (void)actionCancel
{
[self dismissViewControllerAnimated:YES completion:^{
}];
}
///
- (void)actionGo
{
}
/*
#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/10 - DesignPattern(设计模式)/Router/EcoRouterDemo/EcoBaseViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 688 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.