zoukankan      html  css  js  c++  java
  • ios simple code snap

    #define SWITCH_TAG 102

    - (void) updateSwitch:(id)sender 
    {
        // toggle the switch from its current setting
        UISwitch *s = [self.view.window switchWithTag:SWITCH_TAG];
        [s setOn:!s.isOn];
    }

     - (void) updateTime:(id)sender 

    {
        // set the label to the current time
        [self.view.window labelWithTag:LABEL_TAG].text = [[NSDate date] description];
    }
    // This is a private version of the function that appears in my UIView Frame category
    // It's included here as a private function to avoid requiring the other file
    CGRect rectWithCenter(CGRect rect, CGPoint center)
    {
        CGRect newrect = CGRectZero;
        newrect.origin.x = center.x-CGRectGetMidX(rect);
        newrect.origin.y = center.y-CGRectGetMidY(rect);
        newrect.size = rect.size;
        return newrect;

     xcode debug instruction:print po  bt 

    change to GDB debugger:Product”->“Manage Schemes”->Info->Debugger->select GDB 

    relevant  information

    http://blog.163.com/agw_slsyn/blog/static/30915112201213112813356/ 

    http://www.cnblogs.com/lovecode/articles/2343818.html 

    - (void) move: (NSTimer *) aTimer
    {
        // Rotate each iteration by 1% of PI
        CGFloat angle = theta * (M_PI / 100.0f);
        CGAffineTransform transform = CGAffineTransformMakeRotation(angle);
        
        // Theta ranges between 0% and 199% of PI, i.e. between 0 and 2*PI
        theta = (theta + 1) % 200;

        // For fun, scale by the absolute value of the cosine
        float degree = cos(angle);
        if (degree < 0.0) degree *= -1.0f;
        degree += 0.5f;
        
        // Create add scaling to the rotation transform
        CGAffineTransform scaled = CGAffineTransformScale(transform, degree, degree);
        
        // Apply the affine transform
        [[self.view viewWithTag:999] setTransform:scaled];

    }

     - (void) fadeOut: (id) sender

    {
        CGContextRef context = UIGraphicsGetCurrentContext();
        [UIView beginAnimations:nil context:context];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:1.0];
        [[self.view viewWithTag:999] setAlpha:0.0f];
        [UIView commitAnimations];
        self.navigationItem.rightBarButtonItem = BARBUTTON(@"Fade In", @selector(fadeIn:));
    }

    - (void) fadeIn: (id) sender
    {
        CGContextRef context = UIGraphicsGetCurrentContext();
        [UIView beginAnimations:nil context:context];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:1.0];
        [[self.view viewWithTag:999] setAlpha:1.0f];
        [UIView commitAnimations];
        self.navigationItem.rightBarButtonItem = BARBUTTON(@"Fade Out", @selector(fadeOut:));
    }

     - (void) swap: (id) sender

    {
        // hide the button
        self.navigationItem.rightBarButtonItem = nil;
        
        UIView *frontObject = [[self.view subviews] objectAtIndex:2];
        UIView *backObject = [[self.view subviews] objectAtIndex:1];
        
        CGContextRef context = UIGraphicsGetCurrentContext();
        [UIView beginAnimations:nil context:context];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:1.0];
        
        frontObject.alpha = 0.0f;
        backObject.alpha = 1.0f;
        frontObject.transform = CGAffineTransformMakeScale(0.25f0.25f);
        backObject.transform = CGAffineTransformIdentity;
        [self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:2];

        [UIView setAnimationDelegate:self];
        [UIView setAnimationDidStopSelector:@selector(animationFinished:)];
        [UIView commitAnimations];
        
    }

     - (void) flip: (id) sender

    {
        // hide the button
        self.navigationItem.rightBarButtonItem = nil;
        
        CGContextRef context = UIGraphicsGetCurrentContext();
        [UIView beginAnimations:nil context:context];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration:1.0];
        
        UIView *whiteBackdrop = [self.view viewWithTag:100];

        // Choose left or right flip
        if ([(UISegmentedControl *)self.navigationItem.titleView selectedSegmentIndex])
            [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:whiteBackdrop cache:YES];
        else
            [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:whiteBackdrop cache:YES];

        NSInteger purple = [[whiteBackdrop subviews] indexOfObject:[whiteBackdrop viewWithTag:999]];
        NSInteger maroon = [[whiteBackdrop subviews] indexOfObject:[whiteBackdrop viewWithTag:998]];
        [whiteBackdrop exchangeSubviewAtIndex:purple withSubviewAtIndex:maroon];

        [UIView setAnimationDelegate:self];
        [UIView setAnimationDidStopSelector:@selector(animationFinished:)];
        [UIView commitAnimations];
    }
  • 相关阅读:
    ARC和MRC兼容和转换
    ARC下的内存管理
    嵌入式硬件系列一:处理器介绍
    嵌入式Linux GCC常用命令
    一. Linux 下的常用命令
    ARM学习中的必知基本常识
    二叉搜索树详解
    从入门到高手,嵌入式必会技能及学习步骤总结
    史上最全Linux目录结构说明
    排序系列之六:快速排序法进阶
  • 原文地址:https://www.cnblogs.com/zyip/p/2653013.html
Copyright © 2011-2022 走看看