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
//
// YFExchangeMethodVC.h
// BigShow1949
//
// Created by on 16/7/6.
//
#import <UIKit/UIKit.h>
@interface YFExchangeMethodVC : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/RunTime/ExchangeMethod/YFExchangeMethodVC.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 50 |
```objective-c
//
// YFQuartz2DView.h
// BigShow1949
//
// Created by apple on 17/2/23.
//
#import <UIKit/UIKit.h>
@interface YFQuartz2DView : UIView
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/Quartz2D/YFQuartz2DView.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 54 |
```objective-c
//
// YFQuartz2DViewController.m
// BigShow1949
//
// Created by apple on 17/2/23.
//
#import "YFQuartz2DViewController.h"
#import "YFQuartz2DView.h"
@interface YFQuartz2DViewController ()
@end
@implementation YFQuartz2DViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
YFQuartz2DView *customView = [[YFQuartz2DView alloc]initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, self.view.frame.size.height)];
[self.view addSubview:customView];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/Quartz2D/YFQuartz2DViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 248 |
```objective-c
//
// UIImage+Image.m
// BigShow1949
//
// Created by on 16/7/6.
//
#import "UIImage+Image.h"
#import <objc/runtime.h>
@implementation UIImage (Image)
//
+ (void)load
{
// //
// static dispatch_once_t onceToken;
// dispatch_once(&onceToken, ^{
// SEL selA = @selector(imageNamed:);
// SEL selB = @selector(imageWithName:); // B
// Method methodA = class_getInstanceMethod(self,selA);
// Method methodB = class_getInstanceMethod(self, selB);
// BOOL isAdd = class_addMethod(self, selA, method_getImplementation(methodB), method_getTypeEncoding(methodB));
// if (isAdd) {
// class_replaceMethod(self, selB, method_getImplementation(methodA), method_getTypeEncoding(methodA));
// }else{
// method_exchangeImplementations(methodA, methodB);
// }
// });
// imageWithName
Method imageWithName = class_getClassMethod(self, @selector(imageWithName:));
// imageWithName
Method imageName = class_getClassMethod(self, @selector(imageNamed:));
//
method_exchangeImplementations(imageWithName, imageName);
}
// imageNamedsuper.
//
// 1: ,
//+ (instancetype)imageWithName:(NSString *)name
//{
// // imageWithNameimageName
// UIImage *image = [self imageWithName:name];
//
// if (image == nil) {
// NSLog(@"ERROR:");
// }
//
// return image;
//}
// 2: iOS7, _os7,,
// NSString *newName = [name stringByAppendingString:@"_os7"];
+ (instancetype)imageWithName:(NSString *)name
{
BOOL img_iOS7 = [[UIDevice currentDevice].systemVersion floatValue] >= 7.0;
UIImage *image = nil;
if (img_iOS7) {
NSString *newName = [name stringByAppendingString:@"_os7"];
image = [UIImage imageWithName:newName];//imageNamed:
}
if (image == nil) { // _os7
image = [UIImage imageWithName:name];
}
if (image == nil) { // ,
NSLog(@"ERROR:");
}
return image;
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/RunTime/ExchangeMethod/UIImage+Image.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 508 |
```objective-c
//
// YFQuartz2DViewController.h
// BigShow1949
//
// Created by apple on 17/2/23.
//
#import <UIKit/UIKit.h>
@interface YFQuartz2DViewController : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/Quartz2D/YFQuartz2DViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 54 |
```objective-c
//
// GCDDispatchGroupViewController.m
// BigShow1949
//
// Created by apple on 16/11/18.
//
#import "GCDDispatchGroupViewController.h"
@interface GCDDispatchGroupViewController ()
@end
@implementation GCDDispatchGroupViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
// [self test1];
[self test2];
}
/*
:3,
:Dispatch GroupblockGlobal Group Queue,blockMain Dispatch Queueblock
*/
- (void)test1 {
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_group_t group = dispatch_group_create();
dispatch_group_async(group, queue, ^{
[NSThread sleepForTimeInterval:0.5]; //
NSLog(@"1");
});
dispatch_group_async(group, queue, ^{
[NSThread sleepForTimeInterval:0.5]; //
NSLog(@"2");
});
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
NSLog(@"");
});
dispatch_group_async(group, queue, ^{
[NSThread sleepForTimeInterval:0.5]; //
NSLog(@"3");
});
}
/*
:3, 3, , ,
dispatch_barrier_async dispatch_queue_t dispatch_get_global_queue dispatch_barrier_async dispatch_async
*/
- (void)test2 {
dispatch_queue_t concurrentQueue = dispatch_queue_create("my.concurrent.queue", DISPATCH_QUEUE_CONCURRENT);
dispatch_async(concurrentQueue, ^(){
[NSThread sleepForTimeInterval:0.6];
NSLog(@"dispatch-1");
});
dispatch_async(concurrentQueue, ^(){
[NSThread sleepForTimeInterval:0.8];
NSLog(@"dispatch-2");
});
dispatch_barrier_async(concurrentQueue, ^(){
NSLog(@"dispatch-barrier");
});
dispatch_async(concurrentQueue, ^(){
[NSThread sleepForTimeInterval:0.5];
NSLog(@"dispatch-3");
});
dispatch_async(concurrentQueue, ^(){
[NSThread sleepForTimeInterval:0.5];
NSLog(@"dispatch-4");
});
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/GCD/GCDDispatchGroupViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 468 |
```objective-c
//
// GCDDispatchGroupViewController.h
// BigShow1949
//
// Created by apple on 16/11/18.
//
#import <UIKit/UIKit.h>
@interface GCDDispatchGroupViewController : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/GCD/GCDDispatchGroupViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 52 |
```objective-c
//
// GCDViewController.h
// BigShow1949
//
// Created by apple on 16/11/18.
//
#import "BaseTableViewController.h"
@interface GCDViewController : BaseTableViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/GCD/GCDViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 49 |
```objective-c
//
// YFQuartz2DView.m
// BigShow1949
//
// Created by apple on 17/2/23.
//
#import "YFQuartz2DView.h"
#import <QuartzCore/QuartzCore.h>
#define PI 3.14159265358979323846
@implementation YFQuartz2DView
// drawRect
- (void)drawRect:(CGRect)rect
{
//An opaque type that represents a Quartz 2D drawing environment.
//Quartz 2D,,
CGContextRef context = UIGraphicsGetCurrentContext();
/**/
CGContextSetRGBFillColor (context, 1, 0, 0, 1.0);//
UIFont *font = [UIFont boldSystemFontOfSize:15.0];//
[@"" drawInRect:CGRectMake(10, 20, 80, 20) withFont:font];
[@"" drawInRect:CGRectMake(10, 80, 100, 20) withFont:font];
[@"" drawInRect:CGRectMake(10, 120, 80, 20) withFont:font];
[@"" drawInRect:CGRectMake(10, 160, 110, 20) withFont:font];
[@"" drawInRect:CGRectMake(10, 220, 80, 20) withFont:font];
[@"" drawInRect:CGRectMake(10, 260, 100, 20) withFont:font];
[@"" drawInRect:CGRectMake(10, 300, 100, 20) withFont:font];
[@"" drawInRect:CGRectMake(10, 340, 80, 20) withFont:font];
/**/
//
CGContextSetRGBStrokeColor(context,1,1,1,1.0);//
CGContextSetLineWidth(context, 1.0);//
//void CGContextAddArc(CGContextRef c,CGFloat x, CGFloat y,CGFloat radius,CGFloat startAngle,CGFloat endAngle, int clockwise)1180/ 57.3 180/ 360360/180 2
// x,yradiusstartAngleendAngle clockwise 01
CGContextAddArc(context, 100, 20, 15, 0, 2*PI, 0); //
CGContextDrawPath(context, kCGPathStroke); //
//
CGContextAddArc(context, 150, 30, 30, 0, 2*PI, 0); //
CGContextDrawPath(context, kCGPathFill);//
//
UIColor*aColor = [UIColor colorWithRed:1 green:0.0 blue:0 alpha:1];
CGContextSetFillColorWithColor(context, aColor.CGColor);//
CGContextSetLineWidth(context, 3.0);//
CGContextAddArc(context, 250, 40, 40, 0, 2*PI, 0); //
//kCGPathFill,kCGPathEOFill,kCGPathStroke,kCGPathFillStroke,kCGPathEOFillStroke
CGContextDrawPath(context, kCGPathFillStroke); //
/**/
//
CGPoint aPoints[2];//
aPoints[0] =CGPointMake(100, 80);//1
aPoints[1] =CGPointMake(130, 80);//2
//CGContextAddLines(CGContextRef c, const CGPoint points[],size_t count)
//points[]count
CGContextAddLines(context, aPoints, 2);//
CGContextDrawPath(context, kCGPathStroke); //
//
//
CGContextSetRGBStrokeColor(context, 0, 0, 1, 1);//
CGContextMoveToPoint(context, 140, 80);//p1
//CGContextAddArcToPoint(CGContextRef c, CGFloat x1, CGFloat y1,CGFloat x2, CGFloat y2, CGFloat radius)
//x1,y1p1p2x2,y2p3p3,radius,, ,
CGContextAddArcToPoint(context, 148, 68, 156, 80, 10);
CGContextStrokePath(context);//
//
CGContextMoveToPoint(context, 160, 80);//p1
//CGContextAddArcToPoint(CGContextRef c, CGFloat x1, CGFloat y1,CGFloat x2, CGFloat y2, CGFloat radius)
//x1,y1p1p2x2,y2p3p3,radius,, ,
CGContextAddArcToPoint(context, 168, 68, 176, 80, 10);
CGContextStrokePath(context);//
//
CGContextMoveToPoint(context, 150, 90);//p1
//CGContextAddArcToPoint(CGContextRef c, CGFloat x1, CGFloat y1,CGFloat x2, CGFloat y2, CGFloat radius)
//x1,y1p1p2x2,y2p3p3,radius,, ,
CGContextAddArcToPoint(context, 158, 102, 166, 90, 10);
CGContextStrokePath(context);//
//path_to_url
/**/
CGContextStrokeRect(context,CGRectMake(100, 120, 10, 10));//
CGContextFillRect(context,CGRectMake(120, 120, 10, 10));//
//
CGContextSetLineWidth(context, 2.0);//
aColor = [UIColor blueColor];//blue
CGContextSetFillColorWithColor(context, aColor.CGColor);//
aColor = [UIColor yellowColor];
CGContextSetStrokeColorWithColor(context, aColor.CGColor);//
CGContextAddRect(context,CGRectMake(140, 120, 60, 30));//
CGContextDrawPath(context, kCGPathFillStroke);//
//
//path_to_url
//path_to_url
//quartcore#import <QuartzCore/QuartzCore.h>contextviewQuartz Core
CAGradientLayer *gradient1 = [CAGradientLayer layer];
gradient1.frame = CGRectMake(240, 120, 60, 30);
gradient1.colors = [NSArray arrayWithObjects:(id)[UIColor whiteColor].CGColor,
(id)[UIColor grayColor].CGColor,
(id)[UIColor blackColor].CGColor,
(id)[UIColor yellowColor].CGColor,
(id)[UIColor blueColor].CGColor,
(id)[UIColor redColor].CGColor,
(id)[UIColor greenColor].CGColor,
(id)[UIColor orangeColor].CGColor,
(id)[UIColor brownColor].CGColor,nil];
[self.layer insertSublayer:gradient1 atIndex:0];
//
CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
CGFloat colors[] =
{
1,1,1, 1.00,
1,1,0, 1.00,
1,0,0, 1.00,
1,0,1, 1.00,
0,1,1, 1.00,
0,1,0, 1.00,
0,0,1, 1.00,
0,0,0, 1.00,
};
CGGradientRef gradient = CGGradientCreateWithColorComponents
(rgb, colors, NULL, sizeof(colors)/(sizeof(colors[0])*4));//
CGColorSpaceRelease(rgb);
//
//CGContextSaveGStateCGContextRestoreGState
/*
CGContextSaveGStateCGContextRestoreGState
*/
CGContextSaveGState(context);
CGContextMoveToPoint(context, 220, 90);
CGContextAddLineToPoint(context, 240, 90);
CGContextAddLineToPoint(context, 240, 110);
CGContextAddLineToPoint(context, 220, 110);
CGContextClip(context);//context,
//CGContextDrawLinearGradient(CGContextRef context,CGGradientRef gradient, CGPoint startPoint, CGPoint endPoint,CGGradientDrawingOptions options)
//gradient,startPoint,endPoint,optionsor
CGContextDrawLinearGradient(context, gradient,CGPointMake
(220,90) ,CGPointMake(240,110),
kCGGradientDrawsAfterEndLocation);
CGContextRestoreGState(context);// context
//
CGContextSaveGState(context);
CGContextMoveToPoint(context, 260, 90);
CGContextAddLineToPoint(context, 280, 90);
CGContextAddLineToPoint(context, 280, 100);
CGContextAddLineToPoint(context, 260, 100);
CGContextClip(context);//
//
CGContextDrawLinearGradient(context, gradient,CGPointMake
(260, 90) ,CGPointMake(260, 100),
kCGGradientDrawsAfterEndLocation);
CGContextRestoreGState(context);// context
//
CGContextDrawRadialGradient(context, gradient, CGPointMake(300, 100), 0.0, CGPointMake(300, 100), 10, kCGGradientDrawsBeforeStartLocation);
/**/
//
aColor = [UIColor colorWithRed:0 green:1 blue:1 alpha:1];
CGContextSetFillColorWithColor(context, aColor.CGColor);//
//10
CGContextMoveToPoint(context, 160, 180);
CGContextAddArc(context, 160, 180, 30, -60 * PI / 180, -120 * PI / 180, 1);
CGContextClosePath(context);
CGContextDrawPath(context, kCGPathFillStroke); //
//
CGContextAddEllipseInRect(context, CGRectMake(160, 180, 20, 8)); //
CGContextDrawPath(context, kCGPathFillStroke);
/**/
//
CGPoint sPoints[3];//
sPoints[0] =CGPointMake(100, 220);//1
sPoints[1] =CGPointMake(130, 220);//2
sPoints[2] =CGPointMake(130, 160);//3
CGContextAddLines(context, sPoints, 3);//
CGContextClosePath(context);//
CGContextDrawPath(context, kCGPathFillStroke); //
/**/
float fw = 180;
float fh = 280;
CGContextMoveToPoint(context, fw, fh-20); //
CGContextAddArcToPoint(context, fw, fh, fw-20, fh, 10); //
CGContextAddArcToPoint(context, 120, fh, 120, fh-20, 10); //
CGContextAddArcToPoint(context, 120, 250, fw-20, 250, 10); //
CGContextAddArcToPoint(context, fw, 250, fw, fh-20, 10); //
CGContextClosePath(context);
CGContextDrawPath(context, kCGPathFillStroke); //
/**/
//
CGContextMoveToPoint(context, 120, 300);//Path
CGContextAddQuadCurveToPoint(context,190, 310, 120, 390);//
CGContextStrokePath(context);
//
CGContextMoveToPoint(context, 200, 300);//Path
CGContextAddCurveToPoint(context,250, 280, 250, 400, 280, 300);//
CGContextStrokePath(context);
/**/
UIImage *image = [UIImage imageNamed:@"apple.jpg"];
[image drawInRect:CGRectMake(60, 340, 20, 20)];//
// [image drawAtPoint:CGPointMake(100, 340)];//point
CGContextDrawImage(context, CGRectMake(100, 340, 20, 20), image.CGImage);//path_to_url
// CGContextDrawTiledImage(context, CGRectMake(0, 0, 20, 20), image.CGImage);//
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/Quartz2D/YFQuartz2DView.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 2,518 |
```objective-c
//
// GCDBaseViewController.h
// BigShow1949
//
// Created by big show on 2018/7/24.
//
#import <UIKit/UIKit.h>
@interface GCDBaseViewController : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/GCD/GCDBaseViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 50 |
```objective-c
//
// GCDViewController.m
// BigShow1949
//
// Created by apple on 16/11/18.
//
#import "GCDViewController.h"
@interface GCDViewController ()
@end
@implementation GCDViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setupDataArr:@[@[@"GCD",@"GCDBaseViewController"],
@[@"",@"GCDDispatchGroupViewController"]]];
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/GCD/GCDViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 158 |
```objective-c
//
// YFGuideViewController.m
// BigShow1949
//
// Created by zhht01 on 16/5/10.
//
#import "YFGuideViewController.h"
@implementation YFGuideViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setupDataArr:@[@[@"",@"YFGradualChangeViewController"],
@[@"Keep",@"YFKeepViewController_UIStoryboard"],]];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/GuideView/YFGuideViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 92 |
```objective-c
//
// YFGuideViewController.h
// BigShow1949
//
// Created by zhht01 on 16/5/10.
//
#import "BaseTableViewController.h"
@interface YFGuideViewController : BaseTableViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/GuideView/YFGuideViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 53 |
```objective-c
//
// YFKeepViewController.h
// BigShow1949
//
// Created by zhht01 on 16/5/11.
//
#import "ViewController.h"
@interface YFKeepViewController : ViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/GuideView/Keep/YFKeepViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 49 |
```objective-c
//
// YFKeepViewController.m
// BigShow1949
//
// Created by zhht01 on 16/5/11.
//
#import "YFKeepViewController.h"
#import <MediaPlayer/MediaPlayer.h>
#import <AVFoundation/AVFoundation.h>
@interface YFKeepViewController ()
@property(nonatomic,strong)MPMoviePlayerController *moviePlayer;
@property(nonatomic ,strong)NSTimer *timer;
@property (weak, nonatomic) IBOutlet UIView *alpaView;
@property (weak, nonatomic) IBOutlet UIButton *regiset;
@property (weak, nonatomic) IBOutlet UIButton *login;
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UIPageControl *pageControl;
@property(nonatomic ,strong)AVAudioSession *avaudioSession;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *viewWidth;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *secondViewLeading;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *thirdViewLeading;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *fourViewLeading;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *firstLabelWidth;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *secondLabelWidth;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *thridLabelWidth;
@end
@implementation YFKeepViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationController.navigationBarHidden = YES;
/**
*
*/
self.avaudioSession = [AVAudioSession sharedInstance];
NSError *error = nil;
[self.avaudioSession setCategory:AVAudioSessionCategoryAmbient error:&error];
NSString *urlStr = [[NSBundle mainBundle]pathForResource:@"1.mp4" ofType:nil];
NSURL *url = [NSURL fileURLWithPath:urlStr];
_moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:url];
// _moviePlayer.controlStyle = MPMovieControlStyleDefault;
[_moviePlayer play];
[_moviePlayer.view setFrame:self.view.bounds];
[self.view addSubview:_moviePlayer.view];
_moviePlayer.shouldAutoplay = YES;
[_moviePlayer setControlStyle:MPMovieControlStyleNone];
[_moviePlayer setFullscreen:YES];
[_moviePlayer setRepeatMode:MPMovieRepeatModeOne];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playbackStateChanged)
name:MPMoviePlayerPlaybackStateDidChangeNotification
object:_moviePlayer];
_alpaView.backgroundColor = [UIColor clearColor];
[_moviePlayer.view addSubview:_alpaView];
self.regiset.layer.cornerRadius = 3.0f;
self.regiset.alpha = 0.4f;
self.login.layer.cornerRadius = 3.0f;
self.login.alpha = 0.4f;
self.scrollView.bounces = NO;
self.scrollView.pagingEnabled = YES;
self.pageControl.currentPage = 0;
[self.pageControl addTarget:self action:@selector(pageChanged:) forControlEvents:UIControlEventValueChanged];
[self setupTimer];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)playbackStateChanged{
//
MPMoviePlaybackState playbackState = [_moviePlayer playbackState];
//
switch (playbackState) {
case MPMoviePlaybackStateStopped:
[_moviePlayer play];
break;
case MPMoviePlaybackStatePlaying:
NSLog(@"");
break;
case MPMoviePlaybackStatePaused:
[_moviePlayer play];
break;
case MPMoviePlaybackStateInterrupted:
NSLog(@"");
break;
case MPMoviePlaybackStateSeekingForward:
NSLog(@"");
break;
case MPMoviePlaybackStateSeekingBackward:
NSLog(@"");
break;
default:
NSLog(@"");
break;
}
}
-(void)updateViewConstraints{
[super updateViewConstraints];
self.viewWidth.constant = CGRectGetWidth([UIScreen mainScreen].bounds) *4 ;
self.secondViewLeading.constant = CGRectGetWidth([UIScreen mainScreen].bounds);
self.thirdViewLeading.constant = CGRectGetWidth([UIScreen mainScreen].bounds) *2;
self.fourViewLeading.constant =CGRectGetWidth([UIScreen mainScreen].bounds) *3;
self.firstLabelWidth.constant = CGRectGetWidth([UIScreen mainScreen].bounds);
self.secondLabelWidth.constant =CGRectGetWidth([UIScreen mainScreen].bounds);
self.thridLabelWidth.constant = CGRectGetWidth([UIScreen mainScreen].bounds);
}
//ios
-(BOOL)prefersStatusBarHidden{
return YES;
}
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
-(void)setupTimer{
self.timer = [NSTimer timerWithTimeInterval:3.0f target:self selector:@selector(timerChanged) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop]addTimer:self.timer forMode:NSRunLoopCommonModes];
}
-(void)pageChanged:(UIPageControl *)pageControl{
CGFloat x = (pageControl.currentPage) * [UIScreen mainScreen].bounds.size.width;
[self.scrollView setContentOffset:CGPointMake(x, 0) animated:YES];
}
-(void)timerChanged{
int page = (self.pageControl.currentPage +1) %4;
self.pageControl.currentPage = page;
[self pageChanged:self.pageControl];
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
double page = self.scrollView.contentOffset.x / self.scrollView.bounds.size.width;
self.pageControl.currentPage = page;
if (page== - 1)
{
self.pageControl.currentPage = 3;// 0 1
}
else if (page == 4)
{
self.pageControl.currentPage = 0; // +1,1
[self.scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
}
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
[self.timer invalidate];
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
[self setupTimer];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/GuideView/Keep/YFKeepViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 1,318 |
```objective-c
//
// GCDBaseViewController.m
// BigShow1949
//
// Created by big show on 2018/7/24.
//
#import "GCDBaseViewController.h"
/*
:();
()
dispatch_queue_t q = dispatch_queue_create(...., DISPATCH_QUEUE_SERIAL);
()
dispatch_queue_t q = dispatch_queue_create("......", DISPATCH_QUEUE_CONCURRENT);
GET
dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
GETUI
dispatch_queue_t q = dispatch_get_main_queue();
dispatch_async
dispatch_sync
cpu
N
cpu
*/
@interface GCDBaseViewController ()
@end
@implementation GCDBaseViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
// UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 100, 200, 400)];
// label.text = @"";
// [self.view addSubview:label];
//
[self demo16];
CGFloat maxY = 100;
for (int i = 1; i < 17; i++) {
NSLog(@"i = %d", i);
NSString *mySelStr = [NSString stringWithFormat:@"demo%d", i];
SEL mySEL = NSSelectorFromString(mySelStr);
CGFloat btnY = maxY;
CGFloat btnX = 100;
if (i%2 == 0) {
btnX = 100 + 80 + 10;
}
UIButton *redBtn = [[UIButton alloc] initWithFrame:CGRectMake(btnX, btnY, 80, 44)];
[redBtn setTitle:mySelStr forState:UIControlStateNormal];
[redBtn addTarget:self action:mySEL forControlEvents:UIControlEventTouchUpInside];
redBtn.titleLabel.textColor = [UIColor blackColor];
redBtn.backgroundColor = [UIColor blueColor];
[self.view addSubview:redBtn];
if (i%2 == 0) {
maxY = CGRectGetMaxY(redBtn.frame);
}
}
}
#pragma mark - &
- (void)demo1 { //
dispatch_queue_t queue = dispatch_get_main_queue();
dispatch_sync(queue, ^{
NSLog(@"");
});
}
- (void)demo2 { //
dispatch_queue_t queue = dispatch_get_main_queue();
dispatch_async(queue, ^{
NSLog(@"");
NSLog(@"%d",[NSThread isMainThread]); // 1:
});
}
- (void)demo3 { //
dispatch_queue_t queue = dispatch_queue_create("hmj", DISPATCH_QUEUE_SERIAL);
dispatch_async(queue, ^{
NSLog(@", :%@ ,%d",[NSThread currentThread],[NSThread isMainThread]);
});
dispatch_async(queue, ^{
NSLog(@", :%@ ,%d",[NSThread currentThread],[NSThread isMainThread]);
});
dispatch_async(queue, ^{
NSLog(@", :%@ ,%d",[NSThread currentThread],[NSThread isMainThread]);
});
dispatch_async(queue, ^{
NSLog(@", :%@ ,%d",[NSThread currentThread],[NSThread isMainThread]);
});
/*
2016-05-27 19:52:01.012 GCDTest[30425:575429] , :<NSThread: 0x7fb370d1ad60>{number = 3, name = (null)} ,0
2016-05-27 19:52:01.012 GCDTest[30425:575429] , :<NSThread: 0x7fb370d1ad60>{number = 3, name = (null)} ,0
2016-05-27 19:52:01.012 GCDTest[30425:575429] , :<NSThread: 0x7fb370d1ad60>{number = 3, name = (null)} ,0
2016-05-27 19:52:01.013 GCDTest[30425:575429] , :<NSThread: 0x7fb370d1ad60>{number = 3, name = (null)} ,0
*/
}
- (void)demo4 { // cup
dispatch_queue_t queue = dispatch_queue_create("hmj", DISPATCH_QUEUE_CONCURRENT);
dispatch_async(queue, ^{
[NSThread sleepForTimeInterval:1];
NSLog(@", :%@ ,%d",[NSThread currentThread],[NSThread isMainThread]);
});
dispatch_async(queue, ^{
[NSThread sleepForTimeInterval:1];
NSLog(@", :%@ ,%d",[NSThread currentThread],[NSThread isMainThread]);
});
dispatch_async(queue, ^{
[NSThread sleepForTimeInterval:1];
NSLog(@", :%@ ,%d",[NSThread currentThread],[NSThread isMainThread]);
});
dispatch_async(queue, ^{
[NSThread sleepForTimeInterval:1];
NSLog(@", :%@ ,%d",[NSThread currentThread],[NSThread isMainThread]);
});
/*
018-07-24 22:42:30.189752+0700 BigShow[64518:5519578] , :<NSThread: 0x600000460700>{number = 4, name = (null)} ,0
2018-07-24 22:42:30.189755+0700 BigShow[64518:5519585] , :<NSThread: 0x60c00047c600>{number = 3, name = (null)} ,0
2018-07-24 22:42:30.189777+0700 BigShow[64518:5519584] , :<NSThread: 0x608000270c40>{number = 6, name = (null)} ,0
2018-07-24 22:42:30.189782+0700 BigShow[64518:5519583] , :<NSThread: 0x604000265640>{number = 5, name = (null)} ,0
*/
}
- (void)demo5 { //
dispatch_queue_t queue = dispatch_queue_create("hmj", DISPATCH_QUEUE_SERIAL);
dispatch_sync(queue, ^{
NSLog(@", :%@ ,%d",[NSThread currentThread],[NSThread isMainThread]);
});
dispatch_sync(queue, ^{
NSLog(@", :%@ ,%d",[NSThread currentThread],[NSThread isMainThread]);
});
dispatch_sync(queue, ^{
NSLog(@", :%@ ,%d",[NSThread currentThread],[NSThread isMainThread]);
});
dispatch_sync(queue, ^{
NSLog(@", :%@ ,%d",[NSThread currentThread],[NSThread isMainThread]);
});
/*
2018-07-24 22:53:13.343081+0700 BigShow[64737:5533013] , :<NSThread: 0x60400007ad80>{number = 1, name = main} ,1
2018-07-24 22:53:13.343308+0700 BigShow[64737:5533013] , :<NSThread: 0x60400007ad80>{number = 1, name = main} ,1
2018-07-24 22:53:13.343470+0700 BigShow[64737:5533013] , :<NSThread: 0x60400007ad80>{number = 1, name = main} ,1
2018-07-24 22:53:13.343627+0700 BigShow[64737:5533013] , :<NSThread: 0x60400007ad80>{number = 1, name = main} ,1
*/
}
- (void)demo6 { //
dispatch_queue_t queue = dispatch_queue_create("hmj", DISPATCH_QUEUE_CONCURRENT);
dispatch_sync(queue, ^{
[NSThread sleepForTimeInterval:1];
NSLog(@", :%@ ,%d",[NSThread currentThread],[NSThread isMainThread]);
});
dispatch_sync(queue, ^{
[NSThread sleepForTimeInterval:1];
NSLog(@", :%@ ,%d",[NSThread currentThread],[NSThread isMainThread]);
});
dispatch_sync(queue, ^{
[NSThread sleepForTimeInterval:1];
NSLog(@", :%@ ,%d",[NSThread currentThread],[NSThread isMainThread]);
});
dispatch_sync(queue, ^{
[NSThread sleepForTimeInterval:1];
NSLog(@", :%@ ,%d",[NSThread currentThread],[NSThread isMainThread]);
});
/*
2018-07-24 22:53:59.145025+0700 BigShow[64837:5534781] , :<NSThread: 0x60c00007e440>{number = 1, name = main} ,1
2018-07-24 22:54:00.145592+0700 BigShow[64837:5534781] , :<NSThread: 0x60c00007e440>{number = 1, name = main} ,1
2018-07-24 22:54:01.146278+0700 BigShow[64837:5534781] , :<NSThread: 0x60c00007e440>{number = 1, name = main} ,1
2018-07-24 22:54:02.146797+0700 BigShow[64837:5534781] , :<NSThread: 0x60c00007e440>{number = 1, name = main} ,1
*/
}
#pragma mark -
- (void)demo7 { //
dispatch_async(dispatch_get_global_queue(0,0),^{
NSLog(@"Start task 1");
[NSThread sleepForTimeInterval:3];
dispatch_async(dispatch_get_main_queue(),^{
//UI
NSLog(@"UI");
});
});
}
- (void)demo8 { //
/*
#define DISPATCH_QUEUE_PRIORITY_HIGH 2
#define DISPATCH_QUEUE_PRIORITY_DEFAULT 0
#define DISPATCH_QUEUE_PRIORITY_LOW (-2)
#define DISPATCH_QUEUE_PRIORITY_BACKGROUND INT16_MIN
*/
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSLog(@"start task 1");
NSLog(@", :%@ ,%d",[NSThread currentThread],[NSThread isMainThread]);
[NSThread sleepForTimeInterval:2];
NSLog(@"end task 1");
});
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
NSLog(@"start task 2");
NSLog(@", :%@ ,%d",[NSThread currentThread],[NSThread isMainThread]);
[NSThread sleepForTimeInterval:2];
NSLog(@"end task 2");
});
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
NSLog(@"start task 3");
NSLog(@", :%@ ,%d",[NSThread currentThread],[NSThread isMainThread]);
[NSThread sleepForTimeInterval:2];
NSLog(@"end task 3");
});
/*
2018-07-24 23:57:58.425683+0700 BigShow[65432:5588174] start task 3
2018-07-24 23:57:58.425649+0700 BigShow[65432:5587757] start task 1
2018-07-24 23:57:58.425686+0700 BigShow[65432:5588184] start task 2
2018-07-24 23:58:00.425994+0700 BigShow[65432:5588184] end task 2
2018-07-24 23:58:00.426004+0700 BigShow[65432:5587757] end task 1
2018-07-24 23:58:00.426005+0700 BigShow[65432:5588174] end task 3
2018-07-24 23:58:36.530524+0700 BigShow[65531:5589495] start task 3
2018-07-24 23:58:36.530524+0700 BigShow[65531:5589459] start task 1
2018-07-24 23:58:36.530536+0700 BigShow[65531:5589476] start task 2
2018-07-24 23:58:38.535998+0700 BigShow[65531:5589459] end task 1
2018-07-24 23:58:38.536031+0700 BigShow[65531:5589476] end task 2
2018-07-24 23:58:38.606652+0700 BigShow[65531:5589495] end task 3
2018-07-25 00:03:31.901008+0700 BigShow[65531:5595700] start task 1
2018-07-25 00:03:31.901045+0700 BigShow[65531:5595731] start task 2
2018-07-25 00:03:31.900987+0700 BigShow[65531:5589458] start task 3
2018-07-25 00:03:33.901304+0700 BigShow[65531:5595700] end task 1
2018-07-25 00:03:33.901315+0700 BigShow[65531:5595731] end task 2
2018-07-25 00:03:34.000112+0700 BigShow[65531:5589458] end task 3
*/
}
- (void)demo9 { //
dispatch_queue_t queue = dispatch_queue_create("com.test.gcg.queue", DISPATCH_QUEUE_CONCURRENT);
dispatch_async(queue, ^{
NSLog(@"start task 1");
NSLog(@", :%@ ,%d",[NSThread currentThread],[NSThread isMainThread]);
[NSThread sleepForTimeInterval:2];
NSLog(@"end task 1");
});
dispatch_async(queue, ^{
NSLog(@"start task 2");
NSLog(@", :%@ ,%d",[NSThread currentThread],[NSThread isMainThread]);
[NSThread sleepForTimeInterval:2];
NSLog(@"end task 2");
});
dispatch_async(queue, ^{
NSLog(@"start task 3");
NSLog(@", :%@ ,%d",[NSThread currentThread],[NSThread isMainThread]);
[NSThread sleepForTimeInterval:2];
NSLog(@"end task 3");
});
}
- (void)demo10 { //
NSString *str = @"path_to_url";
NSURL *url = [NSURL URLWithString:str];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSURLSession *session = [NSURLSession sharedSession];
for (int i=0; i<10; i++) {
NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSLog(@"%d---%d",i,i);
}];
[task resume];
}
NSLog(@"end");
// dispatch_queue_t queue1 = dispatch_queue_create("com.test.gcg.group", DISPATCH_QUEUE_CONCURRENT);
// dispatch_group_t group = dispatch_group_create();
// dispatch_group_async(group, queue1, ^{
// NSLog(@"start task 1");
// [NSThread sleepForTimeInterval:2];
// NSLog(@"end task 1");
// });
// dispatch_group_async(group, queue1, ^{
// NSLog(@"start task 2");
// [NSThread sleepForTimeInterval:2];
// NSLog(@"end task 2");
// });
// dispatch_group_async(group, queue1, ^{
// NSLog(@"start task 3");
// [NSThread sleepForTimeInterval:2];
// NSLog(@"end task 3");
// });
//
// NSLog(@"====end");
}
- (void)demo11 { // dispatch_group_t
NSLog(@"============================ demo11");
/*
:
dispatch_group_notify
dispatch_group_enter(group);
dispatch_group_leave(group);
*/
dispatch_queue_t queue1 = dispatch_queue_create("com.test.gcg.group", DISPATCH_QUEUE_CONCURRENT);
dispatch_group_t group = dispatch_group_create();
dispatch_group_enter(group);
[self sendRequest1:^{
NSLog(@"request1 done");
dispatch_group_leave(group);
}];
dispatch_group_enter(group);
[self sendRequest2:^{
NSLog(@"request2 done");
dispatch_group_leave(group);
}];
dispatch_group_notify(group, queue1, ^{
NSLog(@"All tasks over");
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"UI");
});
});
}
-(void)sendRequest1:(void(^)())block{
dispatch_async(dispatch_get_global_queue(0,0),^{
NSLog(@"start task 1");
[NSThread sleepForTimeInterval:2];
NSLog(@"end task 1");
dispatch_async(dispatch_get_main_queue(),^{
if(block){
block();
}
});
});
}
-(void)sendRequest2:(void(^)())block{
dispatch_async(dispatch_get_global_queue(0,0),^{
NSLog(@"start task 2");
[NSThread sleepForTimeInterval:2];
NSLog(@"end task 2");
dispatch_async(dispatch_get_main_queue(),^{
if(block){
block();
}
});
});
}
- (void)demo12 { // GCD dispatch_semaphore_t
NSLog(@"============================ demo12");
NSString *str = @"path_to_url";
NSURL *url = [NSURL URLWithString:str];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSURLSession *session = [NSURLSession sharedSession];
// semaphore1-10
dispatch_semaphore_t sem = dispatch_semaphore_create(0);
__block NSInteger count = 0;
for (int i=0; i<10; i++) {
NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSLog(@"%d---%d",i,i);
count++;
if (count==10) {
dispatch_semaphore_signal(sem); // 10
count = 0;
}
}];
[task resume];
}
// 0
dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER); // DISPATCH_TIME_FOREVER
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"end");
});
/*
2018-07-25 14:37:56.508104+0700 BigShow[70482:5837307] 0---0
2018-07-25 14:37:56.570436+0700 BigShow[70482:5837307] 3---3
2018-07-25 14:37:56.644082+0700 BigShow[70482:5837308] 1---1
2018-07-25 14:37:56.700738+0700 BigShow[70482:5837307] 2---2
2018-07-25 14:37:56.722227+0700 BigShow[70482:5837308] 4---4
2018-07-25 14:37:56.810692+0700 BigShow[70482:5837307] 5---5
2018-07-25 14:37:56.871034+0700 BigShow[70482:5837321] 6---6
2018-07-25 14:37:56.929290+0700 BigShow[70482:5837494] 7---7
2018-07-25 14:37:57.013721+0700 BigShow[70482:5837308] 9---9
2018-07-25 14:37:57.133674+0700 BigShow[70482:5837321] 8---8
2018-07-25 14:37:57.148330+0700 BigShow[70482:5837246] end
*/
}
// QWHY3q
- (void)demo13 { // 10enddemo14
NSLog(@":%@ ,%d",[NSThread currentThread],[NSThread isMainThread]);
NSLog(@"============================ demo13");
NSString *str = @"path_to_url";
NSURL *url = [NSURL URLWithString:str];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSURLSession *session = [NSURLSession sharedSession];
NSMutableArray *operationArr = [[NSMutableArray alloc]init];
for (int i=0; i<10; i++) {
NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
NSLog(@":%@ ,%d",[NSThread currentThread],[NSThread isMainThread]);
NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSLog(@"%d---%d",i,i);
}];
[task resume];
//
NSLog(@"noRequest-%d",i);
}];
[operationArr addObject:operation];
if (i>0) {
NSBlockOperation *operation1 = operationArr[i-1];
NSBlockOperation *operation2 = operationArr[i];
[operation2 addDependency:operation1];
}
}
NSOperationQueue *queue = [[NSOperationQueue alloc]init];
queue.maxConcurrentOperationCount = 10;
[queue addOperations:operationArr waitUntilFinished:NO]; //YES
#warning - Operation,,
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"end");
});
}
- (void)demo14 { // demo13semaphore
NSLog(@"============================ demo14");
NSString *str = @"path_to_url";
// NSString *str = @"path_to_url";
NSURL *url = [NSURL URLWithString:str];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSURLSession *session = [NSURLSession sharedSession];
dispatch_semaphore_t sem = dispatch_semaphore_create(0);
for (int i=0; i<10; i++) {
NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSLog(@"%d---%d",i,i);
dispatch_semaphore_signal(sem);
}];
[task resume];
dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
// UI
}
/*
>>>1>,
>>1>,
>>1>,
*/
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"end");
});
}
- (void)demo15 {
/**
ABC
1. 3
2. CB
3. BA
*/
//
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
//
queue.maxConcurrentOperationCount = 3;
//
NSBlockOperation *operationA = [NSBlockOperation blockOperationWithBlock:^{
NSLog(@"A%@", [NSThread currentThread]);
}];
NSBlockOperation *operationB = [NSBlockOperation blockOperationWithBlock:^{
NSLog(@"B%@", [NSThread currentThread]);
}];
NSBlockOperation *operationC = [NSBlockOperation blockOperationWithBlock:^{
NSLog(@"C%@", [NSThread currentThread]);
}];
NSLog(@"===== end");
//
// operationB operationA
[operationA addDependency:operationB];
// operationC operationB
[operationB addDependency:operationC];
//
[queue addOperation:operationA];
[queue addOperation:operationB];
[queue addOperation:operationC];
}
- (void)demo16 {
//
dispatch_group_t group =dispatch_group_create();
//
dispatch_queue_t queue =dispatch_queue_create("queue",DISPATCH_QUEUE_CONCURRENT);
//
dispatch_group_enter(group);
dispatch_async(queue, ^{
void (^task)(void) = ^{
[NSThread sleepForTimeInterval:2];//
NSLog(@"11111 %@", [NSThread currentThread]);
dispatch_group_leave(group);
};
dispatch_async(dispatch_get_global_queue(0,0), task);
NSLog(@"11111---- %@", [NSThread currentThread]);
});
//
dispatch_group_enter(group);
dispatch_async(queue, ^{
void (^task)(void) = ^ {
[NSThread sleepForTimeInterval:1];//
NSLog(@"2222 %@", [NSThread currentThread]);
dispatch_group_leave(group);
};
dispatch_async(dispatch_get_global_queue(0,0), task);
NSLog(@"2222------- %@", [NSThread currentThread]);
});
//block
dispatch_group_notify(group, queue, ^{
NSLog(@" %@", [NSThread currentThread]);
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"UI %@", [NSThread currentThread]);
});
});
NSLog(@"================ ");
/*
2017-10-24 11:48:05.641 iOSTest[35128:902591] 11111---- {number = 3, name = (null)}
2017-10-2411:48:05.641 iOSTest[35128:902608] 2222------- {number = 4, name = (null)}
2017-10-24 11:48:06.644iOSTest[35128:902609] 2222 0x60000006cb00>{number = 5, name = (null)}
2017-10-24 11:48:07.644iOSTest[35128:902593] 11111 0x6080000721c0>{number = 6, name = (null)}
2017-10-24 11:48:07.644iOSTest[35128:902593] 0x6080000721c0>{number = 6, name = (null)}
2017-10-24 11:48:07.645iOSTest[35128:902524] UI 0x61000006e280>{number = 1, name = main}
*/
}
/*
path_to_url
path_to_url
*/
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/GCD/GCDBaseViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 5,827 |
```objective-c
//
// YFGradualChangeViewController.h
// BigShow1949
//
// Created by zhht01 on 16/5/10.
//
#import "ViewController.h"
@interface YFGradualChangeViewController : ViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/GuideView/ZWIntroductionViewController/YFGradualChangeViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 53 |
```objective-c
//
// LGIntroductionViewController.m
//
// Created by square on 15/1/21.
//
#import "ZWIntroductionViewController.h"
@interface ZWIntroductionViewController () <UIScrollViewDelegate>
@property (nonatomic, strong) NSArray *backgroundViews;
@property (nonatomic, strong) NSArray *scrollViewPages;
@property (nonatomic, strong) UIPageControl *pageControl;
@property (nonatomic, assign) NSInteger centerPageIndex;
@end
@implementation ZWIntroductionViewController
- (void)dealloc
{
self.view = nil;
}
- (id)initWithCoverImageNames:(NSArray *)coverNames
{
if (self = [super init]) {
[self initSelfWithCoverNames:coverNames backgroundImageNames:nil];
}
return self;
}
- (id)initWithCoverImageNames:(NSArray *)coverNames backgroundImageNames:(NSArray *)bgNames
{
if (self = [super init]) {
[self initSelfWithCoverNames:coverNames backgroundImageNames:bgNames];
}
return self;
}
- (id)initWithCoverImageNames:(NSArray *)coverNames backgroundImageNames:(NSArray *)bgNames button:(UIButton *)button
{
if (self = [super init]) {
[self initSelfWithCoverNames:coverNames backgroundImageNames:bgNames];
self.enterButton = button;
}
return self;
}
- (void)initSelfWithCoverNames:(NSArray *)coverNames backgroundImageNames:(NSArray *)bgNames
{
self.coverImageNames = coverNames;
self.backgroundImageNames = bgNames;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self addBackgroundViews];
self.pagingScrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
self.pagingScrollView.delegate = self;
self.pagingScrollView.pagingEnabled = YES;
self.pagingScrollView.showsHorizontalScrollIndicator = NO;
[self.view addSubview:self.pagingScrollView];
self.pageControl = [[UIPageControl alloc] initWithFrame:[self frameOfPageControl]];
self.pageControl.pageIndicatorTintColor = [UIColor grayColor];
[self.view addSubview:self.pageControl];
if (!self.enterButton) {
self.enterButton = [UIButton new];
[self.enterButton setTitle:NSLocalizedString(@"Enter", nil) forState:UIControlStateNormal];
self.enterButton.layer.borderWidth = 0.5;
self.enterButton.layer.borderColor = [UIColor whiteColor].CGColor;
}
[self.enterButton addTarget:self action:@selector(enter:) forControlEvents:UIControlEventTouchUpInside];
self.enterButton.frame = [self frameOfEnterButton];
self.enterButton.alpha = 0;
[self.view addSubview:self.enterButton];
[self reloadPages];
}
- (void)addBackgroundViews
{
CGRect frame = self.view.bounds;
NSMutableArray *tmpArray = [NSMutableArray new];
[[[[self backgroundImageNames] reverseObjectEnumerator] allObjects] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:obj]];
imageView.frame = frame;
imageView.tag = idx + 1;
[tmpArray addObject:imageView];
[self.view addSubview:imageView];
}];
self.backgroundViews = [[tmpArray reverseObjectEnumerator] allObjects];
}
- (void)reloadPages
{
self.pageControl.numberOfPages = [[self coverImageNames] count];
self.pagingScrollView.contentSize = [self contentSizeOfScrollView];
__block CGFloat x = 0;
[[self scrollViewPages] enumerateObjectsUsingBlock:^(UIView *obj, NSUInteger idx, BOOL *stop) {
obj.frame = CGRectOffset(obj.frame, x, 0);
[self.pagingScrollView addSubview:obj];
x += obj.frame.size.width;
}];
// fix enterButton can not presenting if ScrollView have only one page
if (self.pageControl.numberOfPages == 1) {
self.enterButton.alpha = 1;
self.pageControl.alpha = 0;
}
// fix ScrollView can not scrolling if it have only one page
if (self.pagingScrollView.contentSize.width == self.pagingScrollView.frame.size.width) {
self.pagingScrollView.contentSize = CGSizeMake(self.pagingScrollView.contentSize.width + 1, self.pagingScrollView.contentSize.height);
}
}
- (CGRect)frameOfPageControl
{
return CGRectMake(0, self.view.bounds.size.height - 30, self.view.bounds.size.width, 30);
}
- (CGRect)frameOfEnterButton
{
CGSize size = self.enterButton.bounds.size;
if (CGSizeEqualToSize(size, CGSizeZero)) {
size = CGSizeMake(self.view.frame.size.width * 0.6, 40);
}
return CGRectMake(self.view.frame.size.width / 2 - size.width / 2, self.pageControl.frame.origin.y - size.height, size.width, size.height);
}
#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSInteger index = scrollView.contentOffset.x / self.view.frame.size.width;
CGFloat alpha = 1 - ((scrollView.contentOffset.x - index * self.view.frame.size.width) / self.view.frame.size.width);
if ([self.backgroundViews count] > index) {
UIView *v = [self.backgroundViews objectAtIndex:index];
if (v) {
[v setAlpha:alpha];
}
}
self.pageControl.currentPage = scrollView.contentOffset.x / (scrollView.contentSize.width / [self numberOfPagesInPagingScrollView]);
[self pagingScrollViewDidChangePages:scrollView];
}
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
if ([scrollView.panGestureRecognizer translationInView:scrollView.superview].x < 0) {
if (![self hasNext:self.pageControl]) {
[self enter:nil];
}
}
}
#pragma mark - UIScrollView & UIPageControl DataSource
- (BOOL)hasNext:(UIPageControl*)pageControl
{
return pageControl.numberOfPages > pageControl.currentPage + 1;
}
- (BOOL)isLast:(UIPageControl*)pageControl
{
return pageControl.numberOfPages == pageControl.currentPage + 1;
}
- (NSInteger)numberOfPagesInPagingScrollView
{
return [[self coverImageNames] count];
}
- (void)pagingScrollViewDidChangePages:(UIScrollView *)pagingScrollView
{
if ([self isLast:self.pageControl]) {
if (self.pageControl.alpha == 1) {
self.enterButton.alpha = 0;
[UIView animateWithDuration:0.4 animations:^{
self.enterButton.alpha = 1;
self.pageControl.alpha = 0;
}];
}
} else {
if (self.pageControl.alpha == 0) {
[UIView animateWithDuration:0.4 animations:^{
self.enterButton.alpha = 0;
self.pageControl.alpha = 1;
}];
}
}
}
- (BOOL)hasEnterButtonInView:(UIView*)page
{
__block BOOL result = NO;
[page.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if (obj && obj == self.enterButton) {
result = YES;
}
}];
return result;
}
- (UIImageView*)scrollViewPage:(NSString*)imageName
{
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];
CGSize size = {[[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height};
imageView.frame = CGRectMake(imageView.frame.origin.x, imageView.frame.origin.y, size.width, size.height);
return imageView;
}
- (NSArray*)scrollViewPages
{
if ([self numberOfPagesInPagingScrollView] == 0) {
return nil;
}
if (_scrollViewPages) {
return _scrollViewPages;
}
NSMutableArray *tmpArray = [NSMutableArray new];
[self.coverImageNames enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
UIImageView *v = [self scrollViewPage:obj];
[tmpArray addObject:v];
}];
_scrollViewPages = tmpArray;
return _scrollViewPages;
}
- (CGSize)contentSizeOfScrollView
{
UIView *view = [[self scrollViewPages] firstObject];
return CGSizeMake(view.frame.size.width * self.scrollViewPages.count, view.frame.size.height);
}
#pragma mark - Action
- (void)enter:(id)object
{
if (self.didSelectedEnter) {
self.didSelectedEnter();
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/GuideView/ZWIntroductionViewController/ZWIntroductionViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 1,778 |
```objective-c
//
// LGIntroductionViewController.h
//
// Created by square on 15/1/21.
//
#import <UIKit/UIKit.h>
typedef void (^DidSelectedEnter)();
@interface ZWIntroductionViewController : UIViewController
@property (nonatomic, strong) UIScrollView *pagingScrollView;
@property (nonatomic, strong) UIButton *enterButton;
@property (nonatomic, copy) DidSelectedEnter didSelectedEnter;
/**
@[@"image1", @"image2"]
*/
@property (nonatomic, strong) NSArray *backgroundImageNames;
/**
@[@"coverImage1", @"coverImage2"]
*/
@property (nonatomic, strong) NSArray *coverImageNames;
- (id)initWithCoverImageNames:(NSArray*)coverNames;
- (id)initWithCoverImageNames:(NSArray*)coverNames backgroundImageNames:(NSArray*)bgNames;
- (id)initWithCoverImageNames:(NSArray*)coverNames backgroundImageNames:(NSArray*)bgNames button:(UIButton*)button;
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/GuideView/ZWIntroductionViewController/ZWIntroductionViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 189 |
```objective-c
//
// YFGradualChangeViewController.m
// BigShow1949
//
// Created by zhht01 on 16/5/10.
//
#import "YFGradualChangeViewController.h"
#import "ZWIntroductionViewController.h"
@interface YFGradualChangeViewController ()
@property (nonatomic, strong) ZWIntroductionViewController *introductionView;
@end
@implementation YFGradualChangeViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationController.navigationBarHidden = YES;
self.view.backgroundColor = [UIColor lightGrayColor];
// Added Introduction View Controller
NSArray *coverImageNames = @[@"img_index_01txt", @"img_index_02txt", @"img_index_03txt"];
NSArray *backgroundImageNames = @[@"img_index_01bg", @"img_index_02bg", @"img_index_03bg"];
self.introductionView = [[ZWIntroductionViewController alloc] initWithCoverImageNames:coverImageNames backgroundImageNames:backgroundImageNames];
// Example 1 : Simple
// self.introductionView = [[ZWIntroductionViewController alloc] initWithCoverImageNames:backgroundImageNames];
// Example 2 : Custom Button
// UIButton *enterButton = [UIButton new];
// [enterButton setBackgroundImage:[UIImage imageNamed:@"bg_bar"] forState:UIControlStateNormal];
// self.introductionView = [[ZWIntroductionViewController alloc] initWithCoverImageNames:coverImageNames backgroundImageNames:backgroundImageNames button:enterButton];
[self.view addSubview:self.introductionView.view];
__weak YFGradualChangeViewController *weakSelf = self;
self.introductionView.didSelectedEnter = ^() {
weakSelf.introductionView = nil;
};
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/GuideView/ZWIntroductionViewController/YFGradualChangeViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 365 |
```objective-c
//
// QRCodeGenerateView.h
// TestQR
//
// Created by apple on 16/11/25.
//
#import <UIKit/UIKit.h>
@interface QRCodeView : UIImageView
/**
@param frame
@param urlString
@return
*/
- (QRCodeView *)initWithFrame:(CGRect)frame urlString:(NSString *)urlString;
/**
*/
@property (nonatomic, strong) UIImage *centerImg;
/**
*/
@property (nonatomic, strong) UIColor *color;
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/QRCode/QRCodeView.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 104 |
```objective-c
//
// QRCodeViewController.h
// BigShow1949
//
// Created by apple on 16/11/25.
//
#import "BaseTableViewController.h"
@interface QRCodeViewController : BaseTableViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/QRCode/QRCodeViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 49 |
```objective-c
//
// QRCodeGenerateViewController.h
// BigShow1949
//
// Created by apple on 16/11/25.
//
#import <UIKit/UIKit.h>
@interface QRCodeGenerateViewController : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/QRCode/QRCodeGenerateViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 48 |
```objective-c
//
// QRCodeViewController.m
// BigShow1949
//
// Created by apple on 16/11/25.
//
#import "QRCodeViewController.h"
@interface QRCodeViewController ()
@end
@implementation QRCodeViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setupDataArr:@[@[@"",@"QRCodeGenerateViewController"]]];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/QRCode/QRCodeViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 166 |
```objective-c
//
// QRCodeGenerateViewController.m
// BigShow1949
//
// Created by apple on 16/11/25.
//
#import "QRCodeGenerateViewController.h"
#import "QRCodeView.h"
@interface QRCodeGenerateViewController ()
@end
@implementation QRCodeGenerateViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
QRCodeView *view = [[QRCodeView alloc] initWithFrame:CGRectMake(100, 100, 100, 100) urlString:@"path_to_url"];
view.centerImg = [UIImage imageNamed:@"i5"];
view.color = [UIColor colorWithRed:200 green:201 blue:202 alpha:1];
[self.view addSubview:view];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/QRCode/QRCodeGenerateViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 154 |
```objective-c
//
// QRCodeGenerateView.m
// TestQR
//
// Created by apple on 16/11/25.
//
#import "QRCodeView.h"
@implementation QRCodeView
#pragma mark - public
- (QRCodeView *)initWithFrame:(CGRect)frame urlString:(NSString *)urlString
{
self = [super initWithFrame:frame];
if (self) {
// 1
CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
//
[filter setDefaults];
// 2
NSString *info = urlString;
NSData *infoData = [info dataUsingEncoding:NSUTF8StringEncoding];
// KVCinputMessage
[filter setValue:infoData forKeyPath:@"inputMessage"];
// 3
CIImage *outputImage = [filter outputImage];
// 4CIImageUIImage
self.image = [self createNonInterpolatedUIImageFormCIImage:outputImage size:self.frame.size.width];
return self;
}
return self;
}
- (void)setCenterImg:(UIImage *)centerImg {
_centerImg = centerImg;
UIImageView *centerImgView = [[UIImageView alloc] init];
centerImgView.image = centerImg;
CGFloat icon_imageW = 20;
CGFloat icon_imageH = icon_imageW;
CGFloat icon_imageX = (self.frame.size.width - icon_imageW) * 0.5;
CGFloat icon_imageY = (self.frame.size.height - icon_imageH) * 0.5;
centerImgView.frame = CGRectMake(icon_imageX, icon_imageY, icon_imageW, icon_imageH);
[self addSubview:centerImgView];
}
- (void)setColor:(UIColor *)color {
_color = color;
NSArray *colorArr = [self getRGBWithColor:color];
CGFloat red = [colorArr[0] floatValue];
CGFloat green = [colorArr[1] floatValue];
CGFloat blue = [colorArr[2] floatValue];
self.image = [self imageBlackToTransparent:self.image withRed:red andGreen:green andBlue:blue];
}
#pragma mark - private
- (UIImage*)imageBlackToTransparent:(UIImage*)image withRed:(CGFloat)red andGreen:(CGFloat)green andBlue:(CGFloat)blue{
const int imageWidth = image.size.width;
const int imageHeight = image.size.height;
size_t bytesPerRow = imageWidth * 4;
uint32_t* rgbImageBuf = (uint32_t*)malloc(bytesPerRow * imageHeight);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(rgbImageBuf, imageWidth, imageHeight, 8, bytesPerRow, colorSpace,
kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipLast);
CGContextDrawImage(context, CGRectMake(0, 0, imageWidth, imageHeight), image.CGImage);
//
int pixelNum = imageWidth * imageHeight;
uint32_t* pCurPtr = rgbImageBuf;
for (int i = 0; i < pixelNum; i++, pCurPtr++){
if ((*pCurPtr & 0xFFFFFF00) < 0x99999900) //
{
//
uint8_t* ptr = (uint8_t*)pCurPtr;
ptr[3] = red; //0~255
ptr[2] = green;
ptr[1] = blue;
}
else
{
uint8_t* ptr = (uint8_t*)pCurPtr;
ptr[0] = 0;
}
}
//
CGDataProviderRef dataProvider = CGDataProviderCreateWithData(NULL, rgbImageBuf, bytesPerRow * imageHeight, ProviderReleaseData);
CGImageRef imageRef = CGImageCreate(imageWidth, imageHeight, 8, 32, bytesPerRow, colorSpace,
kCGImageAlphaLast | kCGBitmapByteOrder32Little, dataProvider,
NULL, true, kCGRenderingIntentDefault);
CGDataProviderRelease(dataProvider);
UIImage* resultUIImage = [UIImage imageWithCGImage:imageRef];
//
CGImageRelease(imageRef);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
return resultUIImage;
}
void ProviderReleaseData (void *info, const void *data, size_t size){
free((void*)data);
}
//
- (UIImage *)createNonInterpolatedUIImageFormCIImage:(CIImage *)ciImage size:(CGFloat)widthAndHeight
{
CGRect extentRect = CGRectIntegral(ciImage.extent);
CGFloat scale = MIN(widthAndHeight / CGRectGetWidth(extentRect), widthAndHeight / CGRectGetHeight(extentRect));
// 1.bitmap;
size_t width = CGRectGetWidth(extentRect) * scale;
size_t height = CGRectGetHeight(extentRect) * scale;
CGColorSpaceRef cs = CGColorSpaceCreateDeviceGray();
CGContextRef bitmapRef = CGBitmapContextCreate(nil, width, height, 8, 0, cs, (CGBitmapInfo)kCGImageAlphaNone);
CIContext *context = [CIContext contextWithOptions:nil];
CGImageRef bitmapImage = [context createCGImage:ciImage fromRect:extentRect];
CGContextSetInterpolationQuality(bitmapRef, kCGInterpolationNone);
CGContextScaleCTM(bitmapRef, scale, scale);
CGContextDrawImage(bitmapRef, extentRect, bitmapImage);
// bitmap
CGImageRef scaledImage = CGBitmapContextCreateImage(bitmapRef);
CGContextRelease(bitmapRef);
CGImageRelease(bitmapImage);
return [UIImage imageWithCGImage:scaledImage]; //
// UIImage *newImage = [UIImage imageWithCGImage:scaledImage];
// return [self imageBlackToTransparent:newImage withRed:200.0f andGreen:200.0f andBlue:200.0f];
}
- (NSArray *)getRGBWithColor:(UIColor *)color
{
CGFloat red = 0.0;
CGFloat green = 0.0;
CGFloat blue = 0.0;
CGFloat alpha = 0.0;
[color getRed:&red green:&green blue:&blue alpha:&alpha];
return @[@(red), @(green), @(blue), @(alpha)];
}
- (NSMutableArray *)changeUIColorToRGB:(UIColor *)color
{
NSMutableArray *RGBStrValueArr = [[NSMutableArray alloc] init];
NSString *RGBStr = nil;
//RGB
NSString *RGBValue = [NSString stringWithFormat:@"%@", color];
//RGB
NSArray *RGBArr = [RGBValue componentsSeparatedByString:@" "];
//
float r = [RGBArr[1] floatValue];
RGBStr = [NSString stringWithFormat:@"%.2lf", r];
[RGBStrValueArr addObject:RGBStr];
//
float g = [RGBArr[2] floatValue];
RGBStr = [NSString stringWithFormat:@"%.2lf", g];
[RGBStrValueArr addObject:RGBStr];
//
float b = [RGBArr[3] floatValue];
RGBStr = [NSString stringWithFormat:@"%.2lf", b];
[RGBStrValueArr addObject:RGBStr];
float a = [RGBArr[4] floatValue];
RGBStr = [NSString stringWithFormat:@"%.2lf", a];
[RGBStrValueArr addObject:RGBStr];
//RGB
return RGBStrValueArr;
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/QRCode/QRCodeView.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 1,617 |
```objective-c
//
// MultipleInheritanceViewController.m
// BigShow1949
//
// Created by apple on 16/11/30.
//
#import "MultipleInheritanceViewController.h"
@interface MultipleInheritanceViewController ()
@end
@implementation MultipleInheritanceViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setupDataArr:@[@[@"",@"MultipleCategory"],
@[@"",@"MultipleCombination"],
@[@"",@"MultipleDelegate"],
@[@"",@"MultipleMsgForawrd"],
@[@"",@"MultipleProtocol"],]];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleInheritanceViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 113 |
```objective-c
//
// MultipleInheritanceViewController.h
// BigShow1949
//
// Created by apple on 16/11/30.
//
#import "BaseTableViewController.h"
@interface MultipleInheritanceViewController : BaseTableViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleInheritanceViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 51 |
```objective-c
//
// Dancer_MC.h
// BigShow1949
//
// Created by apple on 16/11/30.
//
#import <Foundation/Foundation.h>
@interface Dancer_MC : NSObject
- (void)dance;
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleCategory/Dancer_MC.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 52 |
```objective-c
//
// Student_MC.m
// BigShow1949
//
// Created by apple on 16/11/30.
//
#import "Student_MC.h"
@implementation Student_MC
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleCategory/Student_MC.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 42 |
```objective-c
//
// MultipleCategory.h
// BigShow1949
//
// Created by apple on 16/11/30.
//
#import <UIKit/UIKit.h>
@interface MultipleCategory : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleCategory/MultipleCategory.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 44 |
```objective-c
//
// Dancer_MC.m
// BigShow1949
//
// Created by apple on 16/11/30.
//
#import "Dancer_MC.h"
@implementation Dancer_MC
- (void)dance {
NSLog(@"...");
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleCategory/Dancer_MC.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 56 |
```objective-c
//
// Student_MC.h
// BigShow1949
//
// Created by apple on 16/11/30.
//
#import <Foundation/Foundation.h>
@interface Student_MC : NSObject
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleCategory/Student_MC.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 44 |
```objective-c
//
// MultipleCategory.m
// BigShow1949
//
// Created by apple on 16/11/30.
//
#import "MultipleCategory.h"
@interface MultipleCategory ()
@end
@implementation MultipleCategory
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleCategory/MultipleCategory.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 156 |
```objective-c
//
// MultipleDelegate.m
// BigShow1949
//
// Created by apple on 16/11/30.
//
#import "MultipleDelegate.h"
@interface MultipleDelegate ()
@end
@implementation MultipleDelegate
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleDelegate/MultipleDelegate.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 155 |
```objective-c
//
// My.h
// test2
//
// Created by apple on 16/11/30.
//
#import <Foundation/Foundation.h>
@protocol MyDelegate
- (void)buyIphone:(NSString *)iphoneType money:(NSString *)money;
@end
@interface My : NSObject
@property(assign,nonatomic)id<MyDelegate> delegate;
- (void)willbuy;
- (void)buyIphone:(NSString *)iphoneType money:(NSString *)money;
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleDelegate/My.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 99 |
```objective-c
//
// MultipleDelegate.h
// BigShow1949
//
// Created by apple on 16/11/30.
//
#import <UIKit/UIKit.h>
@interface MultipleDelegate : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleDelegate/MultipleDelegate.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 44 |
```objective-c
//
// My.m
// test2
//
// Created by apple on 16/11/30.
//
#import "My.h"
@implementation My
- (void)willbuy {
[_delegate buyIphone:@"iphone" money:@"5000"];
}
-(void)buyIphone:(NSString *)iphoneType money:(NSString *)money {
[_delegate buyIphone:iphoneType money:money];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleDelegate/My.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 90 |
```objective-c
//
// Business.m
// test2
//
// Created by apple on 16/11/30.
//
#import "Business.h"
@implementation Business
-(void)buyIphone:(NSString *)iphoneType money:(NSString *)money
{
NSLog(@"!!");
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleDelegate/Business.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 60 |
```objective-c
//
// Business.h
// test2
//
// Created by apple on 16/11/30.
//
#import <Foundation/Foundation.h>
#import "My.h"
@interface Business : NSObject<MyDelegate>
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleDelegate/Business.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 47 |
```objective-c
//
// Lawyer.h
// test2
//
// Created by apple on 16/11/30.
//
#import <Foundation/Foundation.h>
@interface Lawyer_MMF : NSObject
- (void)speak;
- (void)operate2;
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleMsgForawrd/Lawyer_MMF.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 55 |
```objective-c
//
// MultipleMsgForawrd.h
// BigShow1949
//
// Created by apple on 16/11/30.
//
#import <UIKit/UIKit.h>
@interface MultipleMsgForawrd : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleMsgForawrd/MultipleMsgForawrd.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 50 |
```objective-c
//
// Doctor.h
// test2
//
// Created by apple on 16/11/30.
//
#import <Foundation/Foundation.h>
@interface Doctor_MMF : NSObject
- (void)operate;
- (void)operate2;
- (void)operate3;
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleMsgForawrd/Doctor_MMF.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 62 |
```objective-c
//
// Lawyer.m
// test2
//
// Created by apple on 16/11/30.
//
#import "Lawyer_MMF.h"
@implementation Lawyer_MMF
- (void)speak {
NSLog(@"speak");
}
- (void)operate2 {
NSLog(@"Lawyer - operate2");
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleMsgForawrd/Lawyer_MMF.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 72 |
```objective-c
//
// Doctor.m
// test2
//
// Created by apple on 16/11/30.
//
#import "Doctor_MMF.h"
@implementation Doctor_MMF
- (void)operate {
NSLog(@"Doctor - operate");
}
- (void)operate2 {
NSLog(@"Doctor - operate2");
}
- (void)operate3 {
NSLog(@"Doctor - operate3");
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleMsgForawrd/Doctor_MMF.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 87 |
```objective-c
//
// MultipleMsgForawrd.m
// BigShow1949
//
// Created by apple on 16/11/30.
//
#import "MultipleMsgForawrd.h"
#import "Teacher_MMF.h"
#import "Lawyer_MMF.h"
#import "Doctor_MMF.h"
@interface MultipleMsgForawrd ()
@end
@implementation MultipleMsgForawrd
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
//
Teacher_MMF *teacher = [[Teacher_MMF alloc] init];
[teacher performSelector:@selector(operate)];
// [teacher performSelector:@selector(speak)];
// ,,
// ,.,.h,Doctoroperate2,teacheroperate,,
// [teacher operate];
// 1,
// [(Doctor *)teacher operate];
// :id,,.
// Lawyeroperate2,teacherLawyeroperate2,Doctoroperate2
// [(id)teacher operate2];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleMsgForawrd/MultipleMsgForawrd.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 302 |
```objective-c
//
// Teacher.h
// test2
//
// Created by apple on 16/11/30.
//
#import <Foundation/Foundation.h>
@interface Teacher_MMF : NSObject
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleMsgForawrd/Teacher_MMF.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 42 |
```objective-c
//
// Dog.m
// test2
//
// Created by apple on 16/11/30.
//
#import "Dog_MP.h"
@implementation Dog_MP
- (void)swim {
NSLog(@"swim");
}
- (void)fly {
NSLog(@"fly");
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleProtocol/Dog_MP.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 66 |
```objective-c
//
// MultipleProtocol.m
// BigShow1949
//
// Created by apple on 16/11/30.
//
#import "MultipleProtocol.h"
#import "Dog_MP.h"
@interface MultipleProtocol ()
@end
@implementation MultipleProtocol
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
//
Dog_MP *dog = [[Dog_MP alloc] init];
[dog swim];
/*
1,,,.,
:DogFishswim,swim,DogFishswim,Fishswim.
*/
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleProtocol/MultipleProtocol.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 210 |
```objective-c
//
// Teacher.m
// test2
//
// Created by apple on 16/11/30.
//
#import "Teacher_MMF.h"
#import "Doctor_MMF.h"
@implementation Teacher_MMF
- (id)forwardingTargetForSelector:(SEL)aSelector
{
Doctor_MMF *doctor = [[Doctor_MMF alloc]init];
if ([doctor respondsToSelector:aSelector]) {
return doctor;
}
return nil;
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleMsgForawrd/Teacher_MMF.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 97 |
```objective-c
//
// Bird.h
// test2
//
// Created by apple on 16/11/30.
//
#import <Foundation/Foundation.h>
@protocol CanFly<NSObject>
- (void)fly;
@end
@interface Bird_MP : NSObject
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleProtocol/Bird_MP.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 55 |
```objective-c
//
// Fish.m
// test2
//
// Created by apple on 16/11/30.
//
#import "Fish_MP.h"
@implementation Fish_MP
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleProtocol/Fish_MP.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 39 |
```objective-c
//
// Bird.m
// test2
//
// Created by apple on 16/11/30.
//
#import "Bird_MP.h"
@implementation Bird_MP
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleProtocol/Bird_MP.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 39 |
```objective-c
//
// Fish.h
// test2
//
// Created by apple on 16/11/30.
//
#import <Foundation/Foundation.h>
@protocol CanSwim<NSObject>
- (void)swim;
@end
@interface Fish_MP : NSObject
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleProtocol/Fish_MP.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 57 |
```objective-c
//
// MultipleProtocol.h
// BigShow1949
//
// Created by apple on 16/11/30.
//
#import <UIKit/UIKit.h>
@interface MultipleProtocol : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleProtocol/MultipleProtocol.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 44 |
```objective-c
//
// Dog.h
// test2
//
// Created by apple on 16/11/30.
//
#import <Foundation/Foundation.h>
#import "Fish_MP.h"
#import "Bird_MP.h"
@interface Dog_MP : NSObject <CanFly,CanSwim>
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleProtocol/Dog_MP.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 60 |
```objective-c
//
// ClassA.h
// test2
//
// Created by apple on 16/11/30.
//
#import <Foundation/Foundation.h>
@interface ClassA : NSObject
- (void)methodA;
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleCombination/ClassA.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 49 |
```objective-c
//
// MultipleCombination.m
// BigShow1949
//
// Created by apple on 16/11/30.
//
#import "MultipleCombination.h"
#import "ClassA.h"
#import "ClassB.h"
#import "ClassC.h"
@interface MultipleCombination ()
@end
@implementation MultipleCombination
- (void)viewDidLoad {
[super viewDidLoad];
//
ClassA *a = [[ClassA alloc] init];
ClassB *b = [[ClassB alloc] init];
ClassC *c = [[ClassC alloc] initWithA:a b:b];
[c methodA];
/*
1,.copy
2,.:ClassAClassBmethodD,ClassC.hAB,ClassC.mmethodD
*/
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleCombination/MultipleCombination.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 252 |
```objective-c
//
// ClassB.h
// test2
//
// Created by apple on 16/11/30.
//
#import <Foundation/Foundation.h>
@interface ClassB : NSObject
- (void)methodB;
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleCombination/ClassB.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 49 |
```objective-c
//
// MultipleCombination.h
// BigShow1949
//
// Created by apple on 16/11/30.
//
#import <UIKit/UIKit.h>
@interface MultipleCombination : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleCombination/MultipleCombination.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 46 |
```objective-c
//
// ClassC.m
// test2
//
// Created by apple on 16/11/30.
//
#import "ClassC.h"
#import "ClassA.h"
#import "ClassB.h"
@interface ClassC()
@property (nonatomic, strong) ClassA *a;
@property (nonatomic, strong) ClassB *b;
@end
@implementation ClassC
-(id)initWithA:(ClassA *)A b:(ClassB *)B{
self = [[ClassC alloc] init];
self.a = A;
self.b = B;
return self;
}
-(void)methodA{
[self.a methodA];
}
-(void)methodB{
[self.b methodB];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleCombination/ClassC.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 153 |
```objective-c
//
// ClassA.m
// test2
//
// Created by apple on 16/11/30.
//
#import "ClassA.h"
@implementation ClassA
- (void)methodA {
NSLog(@"methodA [self class] = %@", [self class]);
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleCombination/ClassA.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 63 |
```objective-c
//
// ClassB.m
// test2
//
// Created by apple on 16/11/30.
//
#import "ClassB.h"
@implementation ClassB
- (void)methodB {
NSLog(@"methodB [self class] = %@", [self class]);
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleCombination/ClassB.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 64 |
```objective-c
//
// ClassC.h
// test2
//
// Created by apple on 16/11/30.
//
#import <Foundation/Foundation.h>
@class ClassA,ClassB;
@interface ClassC : NSObject
-(id)initWithA:(ClassA *)A b:(ClassB *)B;
-(void)methodA;
-(void)methodB;
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MultipleInheritance/MultipleCombination/ClassC.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 77 |
```objective-c
//
// YFNotificationCenterVC.h
// BigShow1949
//
// Created by on 16/7/15.
//
#import <UIKit/UIKit.h>
@interface YFNotificationCenterVC : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/NotificationCenter/YFNotificationCenterVC.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 48 |
```objective-c
//
// YFNotificationCenter3VC.m
// BigShow1949
//
// Created by on 16/7/15.
//
#import "YFNotificationCenter3VC.h"
#import "YFNotification.h"
@implementation YFNotificationCenter3VC
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor redColor];
UIButton *redButton = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
[redButton setTitle:@"" forState:UIControlStateNormal];
[redButton addTarget:self action:@selector(redButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:redButton];
}
- (void)redButtonClick:(UIButton *)btn {
[[YFNotificationCenter defaultCenter] postNotificationName:@"vc3" object:nil];
[self.navigationController popViewControllerAnimated:YES];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/NotificationCenter/YFNotificationCenter3VC.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 176 |
```objective-c
//
// YFNotificationCenterVC.m
// BigShow1949
//
// Created by on 16/7/15.
//
#import "YFNotificationCenterVC.h"
#import "YFNotificationCenter2VC.h"
#import "YFNotification.h"
@implementation YFNotificationCenterVC
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"right" style:UIBarButtonItemStylePlain target:self action:@selector(right)];
[[YFNotificationCenter defaultCenter] addObserver:self selector:@selector(YFTest:) name:@"vc2" object:nil];
[[YFNotificationCenter defaultCenter] addObserver:self selector:@selector(YFTest:) name:@"vc2" object:nil];
}
//-(void)viewWillDisappear:(BOOL)animated {
// [super viewDidAppear:animated];
//
// [[YFNotificationCenter defaultCenter] removeObserver:self];
//}
//- (void)dealloc {
// [[YFNotificationCenter defaultCenter] removeObserver:self];
//}
- (void)YFTest:(YFNotification *)noti {
NSLog(@"YFNotification name = %@", noti.name);
UIButton *redButton = [[UIButton alloc] initWithFrame:CGRectMake(100, 300, 100, 100)];
[redButton setTitle:@"YF" forState:UIControlStateNormal];
redButton.backgroundColor = [UIColor blueColor];
[self.view addSubview:redButton];
}
- (void)right {
YFNotificationCenter2VC *vc = [[YFNotificationCenter2VC alloc] init];
[self.navigationController pushViewController:vc animated:YES];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/NotificationCenter/YFNotificationCenterVC.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 330 |
```objective-c
//
// YFNotificationCenter2VC.h
// BigShow1949
//
// Created by on 16/7/15.
//
#import <UIKit/UIKit.h>
@interface YFNotificationCenter2VC : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/NotificationCenter/YFNotificationCenter2VC.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 50 |
```objective-c
//
// YFNotificationCenter2VC.m
// BigShow1949
//
// Created by on 16/7/15.
//
#import "YFNotificationCenter2VC.h"
#import "YFNotification.h"
@implementation YFNotificationCenter2VC
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor redColor];
UIButton *redButton = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
[redButton setTitle:@"" forState:UIControlStateNormal];
[redButton addTarget:self action:@selector(redButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:redButton];
}
- (void)redButtonClick:(UIButton *)btn {
[[YFNotificationCenter defaultCenter] postNotificationName:@"vc2" object:nil];
[self.navigationController popViewControllerAnimated:YES];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/NotificationCenter/YFNotificationCenter2VC.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 174 |
```objective-c
//
// YFNotification.m
// BigShow1949
//
// Created by on 16/7/15.
//
#import "YFNotification.h"
/**************** YFNotification ****************/
@implementation YFNotification
+ (YFNotification *)notificationWithObserver:(id)observer selector:(SEL)selector name:(nullable NSString *)aName object:(nullable id)anObject {
YFNotification *notification = [[YFNotification alloc] init];
notification.observer = observer;
notification.name = aName;
notification.object = anObject;
notification.selector = selector;
return notification;
}
- (NSString *)description {
return [NSString stringWithFormat:@"observer:%@, name:%@", self.observer, self.name];
}
@end
/**************** YFNotificationCenter ****************/
static YFNotificationCenter *_instance =nil;
@interface YFNotificationCenter ()
@property (nonatomic, strong) NSMutableArray *notiArr;
@end
@implementation YFNotificationCenter
#pragma mark -
- (void)addObserver:(id)observer selector:(SEL)aSelector name:(nullable NSString *)aName object:(nullable id)anObject {
if (!observer || !aSelector) return;
BOOL isContain = NO;
for (YFNotification *noti in _notiArr) {
if ([noti.observer isEqual:observer] && [noti.name isEqualToString:aName]) {
isContain = YES;
}
}
if (!isContain) {
YFNotification *noti = [YFNotification notificationWithObserver:observer selector:aSelector name:aName object:anObject];
[self.notiArr addObject:noti];
}
}
#pragma mark -
- (void)postNotificationName:(NSString *)aName object:(nullable id)anObject {
if (!aName) return;
for (YFNotification *noti in _notiArr) {
if ([noti.name isEqualToString:aName]) {
noti.object = anObject;
[noti.observer performSelector:noti.selector withObject:noti];
}
}
}
- (void)postNotificationObserver:(id)observer name:(NSString *)aName object:(nullable id)anObject {
if (!aName || !observer) return;
for (YFNotification *noti in _notiArr) {
if ([noti.name isEqualToString:aName] && [noti.observer isEqual:observer]) {
noti.object = anObject;
[noti.observer performSelector:noti.selector withObject:noti];
break; // 1observeraName,
}
}
}
#pragma mark -
- (void)removeObserver:(id)observer name:(nullable NSString *)aName object:(nullable id)anObject {
for (YFNotification *noti in _notiArr) {
if ([noti.name isEqualToString:aName] && [noti.observer isEqual:observer]) {
[self.notiArr removeObject:noti];
}
}
}
- (void)removeObserver:(id)observer {
// NSLog(@"_notiArr = %@", _notiArr);
NSMutableArray *tempNotiArr = [NSMutableArray arrayWithArray:_notiArr];
for (YFNotification *noti in tempNotiArr) {
if ([noti.observer isEqual:observer]) {
[_notiArr removeObject:noti];
}
}
// NSLog(@"_notiArr = %@", _notiArr);
}
#pragma mark -
+ (id)allocWithZone:(NSZone *)zone
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_instance = [super allocWithZone:zone];
});
return _instance;
}
+ (YFNotificationCenter *)defaultCenter {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_instance = [[self alloc] init];
});
return _instance;
}
#pragma mark -
- (NSMutableArray *)notiArr{
if (!_notiArr) {
_notiArr =[NSMutableArray array];
}
return _notiArr;
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/NotificationCenter/YFNotification.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 871 |
```objective-c
//
// YFNotification.h
// BigShow1949
//
// Created by on 16/7/15.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN // nonnullnullable
// __nullableNULLnil__nonnull
/**************** YFNotification ****************/
@interface YFNotification : NSObject
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) id observer;
@property (nonatomic, strong) id object;
@property (nonatomic, assign) SEL selector;
+ (YFNotification *)notificationWithObserver:(id)observer selector:(SEL)selector name:(nullable NSString *)aName object:(nullable id)anObject;
@end
/**************** YFNotificationCenter ****************/
@interface YFNotificationCenter : NSObject
+ (YFNotificationCenter *)defaultCenter;
/**
* (observer)
*
* @param observer
* @param aSelector
* @param aName
* @param anObject
*/
- (void)addObserver:(id)observer selector:(SEL)aSelector name:(nullable NSString *)aName object:(nullable id)anObject;
- (void)postNotificationName:(NSString *)aName object:(nullable id)anObject;
/**
* 1,11
*
* @param observer
* @param aName
* @param anObject
*/
- (void)postNotificationObserver:(id)observer name:(NSString *)aName object:(nullable id)anObject;
/**
* observer
*
* @param observer
*/
- (void)removeObserver:(id)observer;
- (void)removeObserver:(id)observer name:(nullable NSString *)aName object:(nullable id)anObject;
@end
NS_ASSUME_NONNULL_END
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/NotificationCenter/YFNotification.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 359 |
```objective-c
//
// YFNotificationCenter3VC.h
// BigShow1949
//
// Created by on 16/7/15.
//
#import <UIKit/UIKit.h>
@interface YFNotificationCenter3VC : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/NotificationCenter/YFNotificationCenter3VC.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 50 |
```objective-c
//
// Case4DataEntity.m
// MasonryExample
//
// Created by zorro on 15/7/31.
//
#import "Case4DataEntity.h"
@implementation Case4DataEntity
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MasonryDemo/Case4DataEntity.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 48 |
```objective-c
//
// Case7ViewController.h
// MasonryExample
//
// Created by zorro on 15/11/30.
//
#import <UIKit/UIKit.h>
@interface Case7ViewController : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MasonryDemo/Case7ViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 46 |
```objective-c
//
// Case6ItemView.h
// MasonryExample
//
// Created by zorro on 15/8/2.
//
#import <UIKit/UIKit.h>
@interface Case6ItemView : UIView
+ (instancetype)newItemWithImage:(UIImage *)image text:(NSString *)text;
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MasonryDemo/Case6ItemView.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 65 |
```objective-c
//
// Case8Cell.m
// MasonryExample
//
// Created by zorro on 15/12/5.
//
#import "Case8Cell.h"
#import "Case8DataEntity.h"
#import "Masonry.h"
@interface Case8Cell ()
@property (strong, nonatomic) UILabel *titleLabel;
@property (strong, nonatomic) UILabel *contentLabel;
@property (strong, nonatomic) UIButton *moreButton;
@property (strong, nonatomic) MASConstraint *contentHeightConstraint;
@property (weak, nonatomic) Case8DataEntity *entity;
@property (strong, nonatomic) NSIndexPath *indexPath;
@end
@implementation Case8Cell
- (void)dealloc {
[self removeObserver:self forKeyPath:@"frame"];
}
#pragma mark - Init
// UITableViewdequeueReusableCellWithIdentifierCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
[self initView];
}
return self;
}
#pragma mark - Public method
- (void)setEntity:(Case8DataEntity *)entity indexPath:(NSIndexPath *)indexPath {
_entity = entity;
_indexPath = indexPath;
_titleLabel.text = [NSString stringWithFormat:@"index: %ld, contentView: %p", (long) indexPath.row, (__bridge void *) self.contentView];
_contentLabel.text = entity.content;
if (_entity.expanded) {
[_contentHeightConstraint uninstall];
} else {
[_contentHeightConstraint install];
}
}
#pragma mark - Actions
- (void)switchExpandedState:(UIButton *)button {
[_delegate case8Cell:self switchExpandedStateWithIndexPath:_indexPath];
}
#pragma mark - Private method
- (void)initView {
[self addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
// Title
_titleLabel = [UILabel new];
[self.contentView addSubview:_titleLabel];
[_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.equalTo(@21);
make.left.and.right.and.top.equalTo(self.contentView).with.insets(UIEdgeInsetsMake(4, 8, 4, 8));
}];
// More button
_moreButton = [UIButton buttonWithType:UIButtonTypeSystem];
[_moreButton setTitle:@"More" forState:UIControlStateNormal];
[_moreButton addTarget:self action:@selector(switchExpandedState:) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:_moreButton];
[_moreButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.equalTo(@32);
make.left.and.right.and.bottom.equalTo(self.contentView);
}];
// Content
// UILabelpreferredMaxLayoutWidthLabel
CGFloat preferredMaxWidth = [UIScreen mainScreen].bounds.size.width - 16;
// Content -
_contentLabel = [UILabel new];
_contentLabel.numberOfLines = 0;
_contentLabel.lineBreakMode = NSLineBreakByCharWrapping;
_contentLabel.clipsToBounds = YES;
_contentLabel.preferredMaxLayoutWidth = preferredMaxWidth; //
[self.contentView addSubview:_contentLabel];
[_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.and.right.equalTo(self.contentView).with.insets(UIEdgeInsetsMake(4, 8, 4, 8));
make.top.equalTo(_titleLabel.mas_bottom).with.offset(4);
make.bottom.equalTo(_moreButton.mas_top).with.offset(-4);
//
_contentHeightConstraint = make.height.equalTo(@64).with.priorityHigh(); // High,,
}];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *, id> *)change context:(void *)context {
NSValue *frameValue = change[NSKeyValueChangeOldKey];
CGFloat oldHeight = [frameValue CGRectValue].size.height;
frameValue = change[NSKeyValueChangeNewKey];
CGFloat newHeight = [frameValue CGRectValue].size.height;
NSLog(@"contentView: %p, height change from: %g, to: %g.", (__bridge void *) self.contentView, oldHeight, newHeight);
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MasonryDemo/Case8Cell.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 863 |
```objective-c
//
// Case6ViewController.m
// MasonryExample
//
// Created by zorro on 15/8/2.
//
#import "Case6ViewController.h"
#import "Case6ItemView.h"
#import "Masonry.h"
@interface Case6ViewController ()
@end
@implementation Case6ViewController
#pragma mark - Life cycle
- (void)viewDidLoad {
[super viewDidLoad];
[self initView];
}
#pragma mark - Private methods
- (void)initView {
//
NSArray *images = @[[UIImage imageNamed:@"dog_small"], [UIImage imageNamed:@"dog_middle"], [UIImage imageNamed:@"dog_big"]];
// 3item
UIView *item1 = [Case6ItemView newItemWithImage:images[0] text:@"Auto layout is a system"];
UIView *item2 = [Case6ItemView newItemWithImage:images[1] text:@"Auto Layout is a system that lets you lay out"];
UIView *item3 = [Case6ItemView newItemWithImage:images[2] text:@"Auto Layout is a system that lets you lay out your apps user interface"];
[self.view addSubview:item1];
[self.view addSubview:item2];
[self.view addSubview:item3];
[item1 mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.view.mas_left).with.offset(8);
make.top.mas_equalTo(self.view.mas_top).with.offset(200);
}];
// itembaseline
[item2 mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(item1.mas_right).with.offset(10);
make.baseline.mas_equalTo(item1.mas_baseline);
}];
// itembaseline
[item3 mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(item2.mas_right).with.offset(10);
make.baseline.mas_equalTo(item1.mas_baseline);
}];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MasonryDemo/Case6ViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 391 |
```objective-c
//
// Created by zorro on 15/12/5.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface Case8DataEntity : NSObject
@property (copy, nonatomic) NSString *content;
@property (assign, nonatomic) BOOL expanded; //
// Cache
@property (assign, nonatomic) CGFloat cellHeight;
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MasonryDemo/Case8DataEntity.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 71 |
```objective-c
//
// Case8ViewController.h
// MasonryExample
//
// Created by zorro on 15/12/5.
//
#import <UIKit/UIKit.h>
@interface Case8ViewController : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MasonryDemo/Case8ViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 46 |
```objective-c
//
// Case4DataEntity.h
// MasonryExample
//
// Created by zorro on 15/7/31.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface Case4DataEntity : NSObject
@property (copy, nonatomic) NSString *title;
@property (copy, nonatomic) NSString *content;
@property (strong, nonatomic) UIImage *avatar;
// Cache
@property (assign, nonatomic) CGFloat cellHeight;
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MasonryDemo/Case4DataEntity.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 97 |
```objective-c
//
// Case4ViewController.h
// MasonryExample
//
// Created by zorro on 15/7/31.
//
#import <UIKit/UIKit.h>
@interface Case4ViewController : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MasonryDemo/Case4ViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 46 |
```objective-c
//
// Case8ViewController.m
// MasonryExample
//
// Created by zorro on 15/12/5.
//
#import "Case8ViewController.h"
#import "Case8Cell.h"
#import "Case8DataEntity.h"
@interface Case8ViewController () <UITableViewDelegate, UITableViewDataSource, Case8CellDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) Case8Cell *templateCell;
@property (nonatomic, strong) NSArray *data;
@end
@implementation Case8ViewController
- (void)viewDidLoad {
[super viewDidLoad];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.estimatedRowHeight = 80.0f;
// Cell
[_tableView registerClass:[Case8Cell class] forCellReuseIdentifier:NSStringFromClass([Case8Cell class])];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self generateData];
[_tableView reloadData];
}
#pragma mark - Case8CellDelegate
- (void)case8Cell:(Case8Cell *)cell switchExpandedStateWithIndexPath:(NSIndexPath *)index {
//
Case8DataEntity *case8DataEntity = _data[(NSUInteger) index.row];
case8DataEntity.expanded = !case8DataEntity.expanded; //
case8DataEntity.cellHeight = 0; //
// **********************************
//
// **********************************
// 1,reload cell,cell,cell
// [_tableView beginUpdates];
// [_tableView endUpdates];
// 2,reload,cell
[_tableView reloadRowsAtIndexPaths:@[index] withRowAnimation:UITableViewRowAnimationFade];
}
#pragma mark - UITableViewDelegate, UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return _data.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (!_templateCell) {
_templateCell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([Case8Cell class])];
}
//
Case8DataEntity *dataEntity = _data[(NSUInteger) indexPath.row];
//
if (dataEntity.cellHeight <= 0) {
//
[_templateCell setEntity:dataEntity indexPath:[NSIndexPath indexPathForRow:-1 inSection:-1]]; // -1logcell
// Cell+1
dataEntity.cellHeight = [_templateCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height + 0.5f;
NSLog(@"Calculate height: %ld", (long) indexPath.row);
} else {
NSLog(@"Get cache %ld", (long) indexPath.row);
}
return dataEntity.cellHeight;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
Case8Cell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([Case8Cell class]) forIndexPath:indexPath];
[cell setEntity:_data[(NSUInteger) indexPath.row] indexPath:indexPath];
cell.delegate = self;
return cell;
}
#pragma mark - Private methods
//
- (void)generateData {
NSMutableArray *tmpData = [NSMutableArray new];
for (int i = 0; i < 20; i++) {
Case8DataEntity *dataEntity = [Case8DataEntity new];
dataEntity.content = [self getText:@"case 8 content. " withRepeat:i * 2 + 10];
[tmpData addObject:dataEntity];
}
_data = tmpData;
}
- (NSString *)getText:(NSString *)text withRepeat:(int)repeat {
Case8ViewController *tesxt = [[Case8ViewController alloc] init];
return [tesxt getText:text withRepeat:repeat];
}
// textrepeat
+ (NSString *)getText:(NSString *)text withRepeat:(int)repeat {
NSMutableString *tmpText = [NSMutableString new];
for (int i = 0; i < repeat; i++) {
[tmpText appendString:text];
}
return tmpText;
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MasonryDemo/Case8ViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 844 |
```objective-c
//
// Case7ViewController.m
// MasonryExample
//
// Created by zorro on 15/11/30.
//
#import "Case7ViewController.h"
#import "Masonry.h"
static CGFloat ParallaxHeaderHeight = 235;
static NSString *CellIdentifier = @"Cell";
@interface Case7ViewController () <UITableViewDataSource, UITableViewDelegate, UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) UIImageView *parallaxHeaderView;
@property (strong, nonatomic) MASConstraint *parallaxHeaderHeightConstraint;
@end
@implementation Case7ViewController
- (void)dealloc {
[_tableView removeObserver:self forKeyPath:@"contentOffset"];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self configTableView];
[self initView];
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 20;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.textLabel.text = @(indexPath.row).stringValue;
return cell;
}
// *************************
// contentOffset
// *************************
// 1scrollViewDidScroll:
//#pragma mark - UIScrollViewDelegate
//- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
// if (scrollView.contentOffset.y < 0) {
// _parallaxHeaderHeightConstraint.equalTo(@(ParallaxHeaderHeight - scrollView.contentOffset.y));
// } else {
// _parallaxHeaderHeightConstraint.equalTo(@(ParallaxHeaderHeight));
// }
//}
// 2KVO
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context {
if ([keyPath isEqualToString:@"contentOffset"]) {
CGPoint contentOffset = ((NSValue *)change[NSKeyValueChangeNewKey]).CGPointValue;
if (contentOffset.y < -ParallaxHeaderHeight) {
_parallaxHeaderHeightConstraint.equalTo(@(-contentOffset.y));
}
}
}
#pragma mark - Private methods
- (void)configTableView {
_tableView.backgroundColor = [UIColor clearColor];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.contentInset = UIEdgeInsetsMake(ParallaxHeaderHeight, 0, 0, 0);
[_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:CellIdentifier];
}
- (void)initView {
_parallaxHeaderView = [UIImageView new];
[self.view insertSubview:_parallaxHeaderView belowSubview:_tableView];
_parallaxHeaderView.contentMode = UIViewContentModeScaleAspectFill;
_parallaxHeaderView.image = [UIImage imageNamed:@"parallax_header_back"];
[_parallaxHeaderView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.and.right.equalTo(self.view);
make.top.equalTo(self.mas_topLayoutGuideBottom);
_parallaxHeaderHeightConstraint = make.height.equalTo(@(ParallaxHeaderHeight));
}];
// Add KVO
[_tableView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MasonryDemo/Case7ViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 645 |
```objective-c
//
// Case5ViewController.h
// MasonryExample
//
// Created by zorro on 15/8/2.
//
#import <UIKit/UIKit.h>
@interface Case5ViewController : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MasonryDemo/Case5ViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 46 |
```objective-c
//
// YFMasonryDemoViewController.h
// BigShow1949
//
// Created by zhht01 on 16/3/24.
//
#import <UIKit/UIKit.h>
@interface YFMasonryDemoViewController : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MasonryDemo/YFMasonryDemoViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 52 |
```objective-c
//
// Case3ViewController.m
// MasonryExample
//
// Created by zorro on 15/5/23.
//
#import "Case3ViewController.h"
#import "Masonry.h"
@interface Case3ViewController ()
@property (weak, nonatomic) IBOutlet UIView *containerView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *containerViewWidthConstraint;
@property (assign, nonatomic) CGFloat maxWidth;
@end
@implementation Case3ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self initView];
//
_maxWidth = _containerViewWidthConstraint.constant;
}
# pragma mark - Actions
- (IBAction)modifyContainerViewWidth:(UISlider *)sender {
if (sender.value) {
//containerView
_containerViewWidthConstraint.constant = sender.value * _maxWidth;
}
}
# pragma mark - Private methods
- (void) initView {
UIView *subView = [UIView new];
subView.backgroundColor = [UIColor redColor];
[_containerView addSubview:subView];
[subView mas_makeConstraints:^(MASConstraintMaker *make) {
//
make.left.equalTo(_containerView.mas_left);
make.top.equalTo(_containerView.mas_top);
make.bottom.equalTo(_containerView.mas_bottom);
//view
make.width.equalTo(_containerView.mas_width).multipliedBy(0.5);
}];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MasonryDemo/Case3ViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 289 |
```objective-c
//
// Created by zorro on 15/12/5.
//
#import "Case8DataEntity.h"
@implementation Case8DataEntity
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MasonryDemo/Case8DataEntity.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 31 |
```objective-c
//
// Case6ViewController.h
// MasonryExample
//
// Created by zorro on 15/8/2.
//
#import <UIKit/UIKit.h>
@interface Case6ViewController : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MasonryDemo/Case6ViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 46 |
```objective-c
//
// Case4Cell.m
// MasonryExample
//
// Created by zorro on 15/7/31.
//
#import "Case4Cell.h"
#import "Case4DataEntity.h"
#import "Masonry.h"
@interface Case4Cell ()
@property (nonatomic, strong) UIImageView *avatarImageView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *contentLabel;
@property (nonatomic, weak) Case4DataEntity *dataEntity;
@end
@implementation Case4Cell
// UITableViewdequeueReusableCellWithIdentifierCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
[self initView];
}
return self;
}
#pragma mark - Public methods
- (void)setupData:(Case4DataEntity *)dataEntity {
_dataEntity = dataEntity;
_avatarImageView.image = dataEntity.avatar;
_titleLabel.text = dataEntity.title;
_contentLabel.text = dataEntity.content;
}
#pragma mark - Private methods
- (void)initView {
self.tag = 1000;
// Avatar
_avatarImageView = [UIImageView new];
[self.contentView addSubview:_avatarImageView];
[_avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.and.height.equalTo(@44);
make.left.and.top.equalTo(self.contentView).with.offset(4);
}];
// Title -
_titleLabel = [UILabel new];
[self.contentView addSubview:_titleLabel];
[_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.equalTo(@22);
make.top.equalTo(self.contentView).with.offset(4);
make.left.equalTo(_avatarImageView.mas_right).with.offset(4);
make.right.equalTo(self.contentView).with.offset(-4);
}];
// UILabelpreferredMaxLayoutWidthLabel
CGFloat preferredMaxWidth = [UIScreen mainScreen].bounds.size.width - 44 - 4 * 3; // 44 = avatar4 * 3padding
// Content -
_contentLabel = [UILabel new];
_contentLabel.numberOfLines = 0;
_contentLabel.preferredMaxLayoutWidth = preferredMaxWidth; //
[self.contentView addSubview:_contentLabel];
[_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(_titleLabel.mas_bottom).with.offset(4);
make.left.equalTo(_avatarImageView.mas_right).with.offset(4);
make.right.equalTo(self.contentView).with.offset(-4);
make.bottom.equalTo(self.contentView).with.offset(-4);
}];
[_contentLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MasonryDemo/Case4Cell.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 564 |
```objective-c
//
// YFMasonryDemoViewController.m
// BigShow1949
//
// Created by zhht01 on 16/3/24.
//
#import "YFMasonryDemoViewController.h"
@interface YFMasonryDemoViewController ()
@end
@implementation YFMasonryDemoViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MasonryDemo/YFMasonryDemoViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 170 |
```objective-c
//
// Case9ViewController.h
// MasonryExample
//
// Created by zorro on 15/12/5.
//
#import <UIKit/UIKit.h>
@interface Case9ViewController : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MasonryDemo/Case9ViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 46 |
```objective-c
//
// Case1ViewController.h
// MasonryExample
//
// Created by zorro on 15/5/13.
//
#import <UIKit/UIKit.h>
@interface Case1ViewController : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MasonryDemo/Case1ViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 46 |
```objective-c
//
// Case4ViewController.m
// MasonryExample
//
// Created by zorro on 15/7/31.
//
#import "Case4ViewController.h"
#import "Case4Cell.h"
#import "Case4DataEntity.h"
// Cell
//#define IOS_8_NEW_FEATURE_SELF_SIZING
@interface Case4ViewController () <UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) Case4Cell *templateCell;
@property (nonatomic, strong) NSArray *data;
@end
@implementation Case4ViewController
#pragma mark - Life cycle
- (void)viewDidLoad {
[super viewDidLoad];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.estimatedRowHeight = 80.0f;
#ifdef IOS_8_NEW_FEATURE_SELF_SIZING
// iOS 8 Self-sizing
if ([UIDevice currentDevice].systemVersion.integerValue > 7) {
_tableView.rowHeight = UITableViewAutomaticDimension;
}
#endif
// Cell
[_tableView registerClass:[Case4Cell class] forCellReuseIdentifier:NSStringFromClass([Case4Cell class])];
[self generateData];
[_tableView reloadData];
}
#pragma mark - UITableViewDelegate, UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return _data.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
#ifdef IOS_8_NEW_FEATURE_SELF_SIZING
// iOS 8 Self-sizing
return UITableViewAutomaticDimension;
#else
if (!_templateCell) {
_templateCell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([Case4Cell class])];
_templateCell.tag = -1000; // For debug dealloc
}
//
Case4DataEntity *dataEntity = _data[(NSUInteger) indexPath.row];
//
if (dataEntity.cellHeight <= 0) {
//
[_templateCell setupData:dataEntity];
// Cell+1
dataEntity.cellHeight = [_templateCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height + 0.5f;
NSLog(@"Calculate: %ld, height: %g", (long) indexPath.row, dataEntity.cellHeight);
} else {
NSLog(@"Get cache: %ld, height: %g", (long) indexPath.row, dataEntity.cellHeight);
}
return dataEntity.cellHeight;
#endif
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
Case4Cell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([Case4Cell class]) forIndexPath:indexPath];
[cell setupData:_data[(NSUInteger) indexPath.row]];
return cell;
}
#pragma mark - Private methods
//
- (void)generateData {
NSMutableArray *tmpData = [NSMutableArray new];
for (int i = 0; i < 20; i++) {
Case4DataEntity *dataEntity = [Case4DataEntity new];
dataEntity.avatar = [UIImage imageNamed:[NSString stringWithFormat:@"bluefaces_%d", (i % 4) + 1]];
dataEntity.title = [NSString stringWithFormat:@"Title: %d", i];
dataEntity.content = [[self class] getText:@"content-" withRepeat:i * 2 + 1];
[tmpData addObject:dataEntity];
}
_data = tmpData;
}
// textrepeat
+ (NSString *)getText:(NSString *)text withRepeat:(int)repeat {
NSMutableString *tmpText = [NSMutableString new];
for (int i = 0; i < repeat; i++) {
[tmpText appendString:text];
}
return tmpText;
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MasonryDemo/Case4ViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 777 |
```objective-c
//
// Case2ViewController.m
// MasonryExample
//
// Created by zorro on 15/5/23.
//
#import "Case2ViewController.h"
#import "Masonry.h"
static const CGFloat IMAGE_SIZE = 32;
@interface Case2ViewController ()
@property (strong, nonatomic) UIView *containerView;
@property (strong, nonatomic) NSMutableArray *imageViews;
@property (strong, nonatomic) NSMutableArray *widthConstraints;
@property (strong, nonatomic) NSArray *imageNames;
@end
@implementation Case2ViewController
- (void)viewDidLoad {
[super viewDidLoad];
_imageViews = [NSMutableArray new];
_widthConstraints = [NSMutableArray new];
_imageNames = @[@"bluefaces_1", @"bluefaces_2", @"bluefaces_3", @"bluefaces_4"];
[self initContainerView];
[self initViews];
}
#pragma mark - Actions
- (IBAction)showOrHideImage:(UISwitch *)sender {
NSUInteger index = (NSUInteger) sender.tag;
MASConstraint *width = _widthConstraints[index];
if (sender.on) {
width.equalTo(@(IMAGE_SIZE));
} else {
width.equalTo(@0);
}
}
#pragma mark - Private methods
- (void)initContainerView {
_containerView = [UIView new];
[self.view addSubview:_containerView];
_containerView.backgroundColor = [UIColor grayColor];
[_containerView mas_makeConstraints:^(MASConstraintMaker *make) {
//View
make.height.equalTo(@(IMAGE_SIZE));
//
make.centerX.equalTo(self.view.mas_centerX);
//View200
make.top.equalTo(self.view.mas_top).offset(200);
}];
}
- (void)initViews {
//imageView
for (NSUInteger i = 0; i < 4; i++) {
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:_imageNames[i]]];
[_imageViews addObject:imageView];
[_containerView addSubview:imageView];
}
//
CGSize imageViewSize = CGSizeMake(IMAGE_SIZE, IMAGE_SIZE);
//imageView
//ViewView==...
UIView __block *lastView = nil;
MASConstraint __block *widthConstraint = nil;
NSUInteger arrayCount = _imageViews.count;
[_imageViews enumerateObjectsUsingBlock:^(UIView *view, NSUInteger idx, BOOL *stop) {
[view mas_makeConstraints:^(MASConstraintMaker *make) {
//
widthConstraint = make.width.equalTo(@(imageViewSize.width));
make.height.equalTo(@(imageViewSize.height));
//
make.left.equalTo(lastView ? lastView.mas_right : view.superview.mas_left);
//
make.centerY.equalTo(view.superview.mas_centerY);
//imageViewview
if (idx == arrayCount - 1) {
make.right.equalTo(view.superview.mas_right);
}
[_widthConstraints addObject:widthConstraint];
lastView = view;
}];
}];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MasonryDemo/Case2ViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 608 |
```objective-c
//
// Case2ViewController.h
// MasonryExample
//
// Created by zorro on 15/5/23.
//
#import <UIKit/UIKit.h>
@interface Case2ViewController : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MasonryDemo/Case2ViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 46 |
```objective-c
//
// Case1ViewController.m
// MasonryExample
//
// Created by zorro on 15/5/13.
//
#import "Case1ViewController.h"
#import "Masonry.h"
@interface Case1ViewController ()
@property (strong, nonatomic) UILabel *label1;
@property (strong, nonatomic) UILabel *label2;
@property (weak, nonatomic) IBOutlet UIView *contentView1;
@end
@implementation Case1ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self initViews];
}
#pragma mark - Actions
- (IBAction)addLabelContent:(UIStepper *)sender {
switch (sender.tag) {
case 0:
_label1.text = [self getLabelContentWithCount:(NSUInteger)sender.value];
break;
case 1:
_label2.text = [self getLabelContentWithCount:(NSUInteger)sender.value];
break;
default:
break;
}
}
#pragma mark - Private methods
- (void)initViews {
_label1 = [UILabel new];
_label1.backgroundColor = [UIColor yellowColor];
_label1.text = @"label,";
_label2 = [UILabel new];
_label2.backgroundColor = [UIColor greenColor];
_label2.text = @"label,";
[_contentView1 addSubview:_label1];
[_contentView1 addSubview:_label2];
// label1:
[_label1 mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(_contentView1.mas_top).with.offset(5);
make.left.equalTo(_contentView1.mas_left).with.offset(2);
// 40
make.height.equalTo(@40);
}];
// label2:
[_label2 mas_makeConstraints:^(MASConstraintMaker *make) {
//label1
make.left.equalTo(_label1.mas_right).with.offset(2);
//view
make.top.equalTo(_contentView1.mas_top).with.offset(5);
//2lessThanOrEqual
//lessThanOrEqualToX
//label2XcontainViewX
make.right.lessThanOrEqualTo(_contentView1.mas_right).with.offset(-2);
//40
make.height.equalTo(@40);
}];
//label1content hugging 1000
[_label1 setContentHuggingPriority:UILayoutPriorityRequired
forAxis:UILayoutConstraintAxisHorizontal];
//label1content compression 1000
[_label1 setContentCompressionResistancePriority:UILayoutPriorityRequired
forAxis:UILayoutConstraintAxisHorizontal];
//label2content hugging 1000
[_label2 setContentHuggingPriority:UILayoutPriorityRequired
forAxis:UILayoutConstraintAxisHorizontal];
//label2content compression 250
[_label2 setContentCompressionResistancePriority:UILayoutPriorityDefaultLow
forAxis:UILayoutConstraintAxisHorizontal];
// Content Hugging Priority
// Content Compression Resistance Priority
}
- (NSString *)getLabelContentWithCount:(NSUInteger)count {
NSMutableString *ret = [NSMutableString new];
for (NSUInteger i = 0; i <= count; i++) {
[ret appendString:@"label,"];
}
return ret.copy;
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MasonryDemo/Case1ViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 666 |
```objective-c
//
// Case5ViewController.m
// MasonryExample
//
// Created by zorro on 15/8/2.
//
#import "Case5ViewController.h"
#import "Masonry.h"
// lengthmas_topLayoutGuidemas_bottomLayoutGuide
#define NEW_FEATURE
@interface Case5ViewController ()
@property (strong, nonatomic) UIView *topView;
@property (strong, nonatomic) UIView *bottomView;
@end
@implementation Case5ViewController
#pragma mark - Life cycle
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"top(bottom)LayoutGuide";
[self initView];
NSLog(@"[viewDidLoad] top: %g", self.topLayoutGuide.length);
}
#pragma mark - Actions
- (IBAction)showOrHideTopBar:(id)sender {
[self.navigationController setNavigationBarHidden:!self.navigationController.navigationBarHidden animated:NO];
// NavigationBarupdateViewConstraints
[self updateViewConstraints];
}
- (IBAction)showOrHideBottomBar:(id)sender {
[self.navigationController setToolbarHidden:!self.navigationController.toolbarHidden animated:NO];
// updateViewConstraints
[self updateViewConstraints];
}
- (IBAction)back:(id)sender {
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - Private methods
- (void)initView {
_topView = [UIView new];
_topView.backgroundColor = [UIColor greenColor];
[self.view addSubview:_topView];
[_topView mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.equalTo(@40);
make.left.and.right.equalTo(self.view);
#ifdef NEW_FEATURE
make.top.equalTo(self.mas_topLayoutGuide);
#endif
}];
_bottomView = [UIView new];
_bottomView.backgroundColor = [UIColor yellowColor];
[self.view addSubview:_bottomView];
[_bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.equalTo(@40);
make.left.and.right.equalTo(self.view);
#ifdef NEW_FEATURE
make.bottom.equalTo(self.mas_bottomLayoutGuide);
#endif
}];
}
#pragma mark - Override
- (void)updateViewConstraints {
#ifndef NEW_FEATURE
// length
[_topView mas_updateConstraints:^(MASConstraintMaker *make) {
// lengthiOSSDKtopLayoutGuideUIView
make.top.equalTo(self.view.mas_top).with.offset(self.topLayoutGuide.length);
}];
// length
[_bottomView mas_updateConstraints:^(MASConstraintMaker *make) {
// lengthiOSSDKtopLayoutGuideUIView
make.bottom.equalTo(self.view.mas_bottom).with.offset(-(self.bottomLayoutGuide.length));
}];
#endif
[super updateViewConstraints];
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MasonryDemo/Case5ViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 549 |
```objective-c
//
// Case8Cell.h
// MasonryExample
//
// Created by zorro on 15/12/5.
//
#import <UIKit/UIKit.h>
@class Case8DataEntity;
@class Case8Cell;
@protocol Case8CellDelegate <NSObject>
- (void)case8Cell:(Case8Cell *)cell switchExpandedStateWithIndexPath:(NSIndexPath *)index;
@end
@interface Case8Cell : UITableViewCell
@property (weak, nonatomic) id <Case8CellDelegate> delegate;
- (void)setEntity:(Case8DataEntity *)entity indexPath:(NSIndexPath *)indexPath;
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MasonryDemo/Case8Cell.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 123 |
```objective-c
//
// Case3ViewController.h
// MasonryExample
//
// Created by zorro on 15/5/23.
//
#import <UIKit/UIKit.h>
@interface Case3ViewController : UIViewController
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MasonryDemo/Case3ViewController.h | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 46 |
```objective-c
//
// Case9ViewController.m
// MasonryExample
//
// Created by zorro on 15/12/5.
//
#import "Case9ViewController.h"
#import "Masonry.h"
static const CGFloat ITEM_SIZE = 32;
static const NSUInteger ITEM_COUNT = 4;
@interface Case9ViewController ()
@property (weak, nonatomic) IBOutlet UIView *containerView1;
@property (weak, nonatomic) IBOutlet UIView *containerView2;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *container1WidthConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *container2WidthConstraint;
@property (assign, nonatomic) CGFloat maxWidth;
@property (strong, nonatomic) NSArray *imageNames;
@end
@implementation Case9ViewController
- (void)viewDidLoad {
[super viewDidLoad];
_maxWidth = _container1WidthConstraint.constant;
_imageNames = @[@"bluefaces_1", @"bluefaces_2", @"bluefaces_3", @"bluefaces_4"];
[self initContainer1];
[self initContainer2];
}
# pragma mark - Actions
- (IBAction)changeContainerViewWidth:(UISlider *)sender {
_container1WidthConstraint.constant = sender.value * _maxWidth;
_container2WidthConstraint.constant = sender.value * _maxWidth;
}
#pragma mark - Private methods
// SpaceView
- (void)initContainer1 {
UIView *lastSpaceView = [UIView new];
lastSpaceView.backgroundColor = [UIColor greenColor];
[_containerView1 addSubview:lastSpaceView];
[lastSpaceView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.and.top.and.bottom.equalTo(_containerView1);
}];
for (NSUInteger i = 0; i < ITEM_COUNT; i++) {
UIView *itemView = [self getItemViewWithIndex:i];
[_containerView1 addSubview:itemView];
[itemView mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.and.width.equalTo(@(ITEM_SIZE));
make.left.equalTo(lastSpaceView.mas_right);
make.centerY.equalTo(_containerView1.mas_centerY);
}];
UIView *spaceView = [UIView new];
spaceView.backgroundColor = [UIColor greenColor];
[_containerView1 addSubview:spaceView];
[spaceView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(itemView.mas_right).with.priorityHigh(); //
make.top.and.bottom.equalTo(_containerView1);
make.width.equalTo(lastSpaceView.mas_width);
}];
lastSpaceView = spaceView;
}
[lastSpaceView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(_containerView1.mas_right);
}];
}
// multiplier
- (void)initContainer2 {
for (NSUInteger i = 0; i < ITEM_COUNT; i++) {
UIView *itemView = [self getItemViewWithIndex:i];
[_containerView2 addSubview:itemView];
[itemView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.and.height.equalTo(@(ITEM_SIZE));
make.centerY.equalTo(_containerView2.mas_centerY);
make.centerX.equalTo(_containerView2.mas_right).multipliedBy(((CGFloat)i + 1) / ((CGFloat)ITEM_COUNT + 1));
}];
}
}
- (UIView *)getItemViewWithIndex:(NSUInteger)index {
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:_imageNames[index % _imageNames.count]]];
imageView.contentMode = UIViewContentModeScaleAspectFit;
return imageView;
}
@end
``` | /content/code_sandbox/BigShow1949/Classes/05 - KnowledgePoint(零散知识点)/MasonryDemo/Case9ViewController.m | objective-c | 2016-05-05T08:19:43 | 2024-08-07T09:29:21 | BigShow1949 | BigShow1949/BigShow1949 | 1,121 | 726 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.