IOS開發基礎知識--片段43,ios基礎知識--43

來源:互聯網
上載者:User

IOS開發基礎知識--片段43,ios基礎知識--43

1:增加手勢進行左劃效果,針對視圖並修改其中一個的座標,菜單用隱藏跟顯示

@property(strong,nonatomic)UISwipeGestureRecognizer *recognizer;
self.recognizer = [[ UISwipeGestureRecognizer alloc ] initWithTarget:self action:@selector (handleSwipeFrom:)];[self.recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];[self addGestureRecognizer :self.recognizer];
- (void)handleSwipeFrom:( UISwipeGestureRecognizer *)sender{if (sender.direction == UISwipeGestureRecognizerDirectionLeft )    {        self.rightButton.hidden=NO;        [self.recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];                        [self.valueLabel mas_remakeConstraints:^(MASConstraintMaker *make) {            make.right.mas_equalTo(self.rightButton.left).with.offset(-5);            make.centerY.mas_equalTo(self).with.offset(0);            make.size.mas_equalTo(CGSizeMake(Main_Screen_Width-180, 15));        }];        [self.valueLabel layoutIfNeeded];    }    else    {        self.rightButton.hidden=YES;        [self.recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];                [self.valueLabel mas_remakeConstraints:^(MASConstraintMaker *make) {            make.right.mas_equalTo(self.right).with.offset(-15);            make.centerY.mas_equalTo(self).with.offset(0);            make.size.mas_equalTo(CGSizeMake(Main_Screen_Width-180, 15));        }];        [self.valueLabel layoutIfNeeded];    }}

 

2:屬性名稱以new開頭解決方式

@property (nonatomic,copy) NSString *new_Passwd;  

像上面這樣寫法會報錯,可以替換成

@property (nonatomic,copy,getter = theNewPasswd) NSString *new_Passwd;

 

3:單例類一些注意事項

如果allocWithZone裡面的代碼不寫,用以下三種建立的執行個體還是三種,不符合我們對單例的運用,當然如果你只針對[HLTestObject sharedInstance]進行執行個體化時,就是一直滿足;把初始化的屬性對象放在sharedInstance裡面,如果放在init裡面進行初始化也會出現不一樣的情景;

HLTestObject *objct1 = [HLTestObject sharedInstance];NSLog(@"%@",objct1);HLTestObject *objc2 = [[HLTestObject alloc] init];NSLog(@"%@",objc2);HLTestObject *objc3 = [HLTestObject new];NSLog(@"%@",objc3);

聲明屬性:

@property (assign, nonatomic)   int  height;@property (strong, nonatomic)   NSObject  *object;@property (strong, nonatomic)   NSMutableArray  *arrayM;

代碼內容:

static HLTestObject *instance = nil;+ (instancetype)sharedInstance{    static dispatch_once_t onceToken;    dispatch_once(&onceToken, ^{        instance = [[[self class] alloc] init];        instance.height = 10;        instance.object = [[NSObject alloc] init];        instance.arrayM = [[NSMutableArray alloc] init];    });    return instance;}+ (instancetype)allocWithZone:(struct _NSZone *)zone{    static dispatch_once_t onceToken;    dispatch_once(&onceToken, ^{        instance = [super allocWithZone:zone];    });    return instance;}- (NSString *)description{    NSString *result = @"";    result = [result stringByAppendingFormat:@"<%@: %p>",[self class], self];    result = [result stringByAppendingFormat:@" height = %d,",self.height];    result = [result stringByAppendingFormat:@" arrayM = %p,",self.arrayM];    result = [result stringByAppendingFormat:@" object = %p,",self.object];    return result;}

4:UITextField實現左側空出一定的邊距

就是通過uitextfield的leftview來實現的,同時要設定leftviewmode。

如果設定左右邊距,需要再加上rightView功能

-(void)setTextFieldLeftPadding:(UITextField *)textField forWidth:(CGFloat)leftWidth{    CGRect frame = textField.frame;    frame.size.width = leftWidth;    UIView *leftview = [[UIView alloc] initWithFrame:frame];    textField.leftViewMode = UITextFieldViewModeAlways;    textField.leftView = leftview;}

 5:UICollectionView非同步載入的執行個體

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{    static NSString * CellIdentifier = @"Event";    EventCollectionViewCell *cell  = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];    Event *event = [events objectAtIndex:indexPath.item];  // replace "Event" with whatever class you use for your items實體    cell.eventTitle.text = [event objectForKey:@"title"];    cell.eventImage.image = [event objectForKey:@"image"];    if (cell.eventImage.image == nil) {        NSString *imageUrl = [[[events objectAtIndex:indexPath.item] objectForKey:@"photo"] objectForKey:@"url"];        dispatch_queue_t imageFetchQ = dispatch_queue_create("image fetched", NULL);        dispatch_async(imageFetchQ, ^{            __weak UICollectionView *weakCollection;            NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrl]];            UIImage *image = [UIImage imageWithData:imageData];            if (image)            {                dispatch_async(dispatch_get_main_queue(), ^{                    [event setObject:image forKey:@"image"]; // updating the model here                    [weakCollection reloadItemsAtIndexPaths:@[indexPath]];                });            }        });    }    return cell;}

6:如何拿到別人APP圖片

a:開啟你Mac上的iTunes,點擊我的應用程式, 找到剛下載好的應用, 右擊在finder中顯示  

b:按Enter(斷行符號鍵), 修改ipa檔案的尾碼為.zip, 即把 6.3.22.ipa變成 6.3.22.zip, 此處會有一個提示, 問你是否確定修改副檔名, 點擊使用.zip即可  

c:直接雙擊zip進行解壓, 開啟解壓好的檔案夾, 進入Payload檔案夾 此時, 就拿到了大多數的資源. 包括css, js, 圖片, MP3/4, 字型,xib等等資源    

d:取Assets.car中的資源 (工具: http://pan.baidu.com/s/1kUVAT7p 提取密碼: qrt5)

e:我們在上面的E步驟所在的檔案夾處搜尋Assets.car即可 直接將Assets.car拖入其中即可, 對, 拖進去就行了,點擊start, 完成後, 點擊Output Dir即可( iOS APP中所有資源 =  Assets.car +  .api檔案解壓)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

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

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