ios simple code snap

來源:互聯網
上載者:User

 

#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.25f, 0.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];
}

 

 

 

 

 

 

 

 

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.