NSTimer 暂停和恢复

没有评论

2012 年 5 月 9 日 at 上午 9:50分类:Development | iOS

-(void) pauseTimer:(NSTimer *)timer { 

    pauseStart = [[NSDate dateWithTimeIntervalSinceNow:0] retain];

    previousFireDate = [[timer fireDate] retain];

    [timer setFireDate:[NSDate distantFuture]];
}

-(void) resumeTimer:(NSTimer *)timer {

//    NSLog(@"pauseStart retain count: %d", [pauseStart retainCount]);
//    NSLog(@"pauseStart: %@",pauseStart);

    float pauseTime = -1*[pauseStart timeIntervalSinceNow]; //pauseTime 就是暂停时间,可以手动设成几秒, 相当于延迟触发

    [timer setFireDate:[previousFireDate initWithTimeInterval:pauseTime sinceDate:previousFireDate]];

    [pauseStart release];
    [previousFireDate release];
}

UIScrollView 页码计算 & 定位页面显示的起点

没有评论

2012 年 5 月 9 日 at 上午 9:46分类:Development | iOS

- (void) snapToPosition:(UIScrollView *) scrollView {

    CGFloat itemWidth = 988;

    CGFloat pageWidth = scrollView.frame.size.width;
    int page = floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;

    NSLog(@"page: %d", page);
    [scrollView setContentOffset:CGPointMake(itemWidth*page, 0.0f) animated:YES];

//    第二种方法
//    CGFloat itemWidth = 988;
//    CGFloat position = [scrollView contentOffset].x;
//    CGFloat newPosition = 0.0f;
//    CGFloat offSet = position / itemWidth;
//    NSUInteger target = (NSUInteger)(offSet + 0.5f);
//
//    newPosition = target * itemWidth;
//    [scrollView setContentOffset:CGPointMake(newPosition, 0.0f) animated:YES];

}

[笔记] 一种view显示的特效

没有评论

2012 年 4 月 23 日 at 下午 4:36分类:Development | iOS

一种特效。留个记录。。

 CATransition *animation = [CATransition animation];
    [animation setDuration:1.25f];
    [animation setTimingFunction:[CAMediaTimingFunction
                                  functionWithName:kCAMediaTimingFunctionEaseIn]];
    [animation setType:kCATransitionReveal];
    [animation setSubtype: kCATransitionFromBottom];
    [self.view.layer addAnimation:animation forKey:@"Reveal"];
    [super viewWillAppear:animated];

[笔记] iOS 设置presentModalViewController的大小

没有评论

2012 年 4 月 23 日 at 下午 4:18分类:Development | iOS

做的一个app的弹出设置页面但是发现系统默认的太大了,网上找到设置这个UINavigationController所在的superview(presentModalViewController)大小的方法,在下面代码的后两行:

SettingViewController   *settingViewController = [[SettingViewController alloc] initWithStyle:UITableViewStyleGrouped];
    UINavigationController *settingNav = [[UINavigationController alloc] initWithRootViewController:settingViewController];

    settingNav.modalPresentationStyle = UIModalPresentationFormSheet ;
    settingNav.modalTransitionStyle = UIModalTransitionStyleCoverVertical ;

    [self presentModalViewController:settingNav animated:YES] ;

    //下面设置presentModalViewController的大小
    settingNav.view.superview.frame = CGRectMake(0, 0, 512, 374);
    settingNav.view.superview.center = self.view.center;
    //这句有时候获取到的并不是正中,我的情况就是,然后用了下面的这个固定坐标
    settingNav.view.superview.center = CGPointMake(512,374);

btw,用这样生成的就是像新浪微博HD,QQ HD等等软件的那个系统设置页面。同时带有从底部到屏幕正中的动画。

[笔记] UIView半透明黑色背景

没有评论

2012 年 4 月 23 日 at 下午 3:31分类:Development | iOS

view.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.5];

[笔记] 自定义UIView圆角

没有评论

2012 年 4 月 23 日 at 下午 3:06分类:Development | iOS

#import <QuartzCore/QuartzCore.h>

    CGFloat cornerRadiusInPixels = 5.0;
    View.layer.cornerRadius = cornerRadiusInPixels;
    View.layer.masksToBounds = YES;
    View.opaque = NO;

[笔记] iOS Using Application Preferences

没有评论

2012 年 4 月 6 日 at 下午 2:18分类:Development | iOS

Adding application preferences to your application

Add a Settings Bundle file to your project and modify the Root.plist file.

Loading the value of a preference setting

//In Delegate.m File
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if (![defaults objectForKey:@"login_name"]) {
        [defaults setObject:@"login name" forKey:@"login_name"];
    }
[defaults synchronize];
//In ViewController.m File
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
loginName.text = [defaults objectForKey:@”login_name”];

Resetting preferences settings values

Remove the entire application either from the Home screen or via the iPhone Simulator folder on your Mac.

Saving the value of a preference setting 

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:loginName.text forKey:@”login_name”];

[defaults synchronize];

[笔记] iOS TableView

没有评论

2012 年 4 月 5 日 at 下午 4:30分类:Development | iOS

Adding items to a Table view

Handle the various events in the UITableViewDataSource protocol.

Allowing users to select rows in a Table view

Handle the various events in the UITableViewDelegate protocol.

Adding images to rows in a Table view

Use the image property of the UITableViewCell class and set it to an instance of the UIImage class containing an image.

Using a property list with a Table view

Use the following code snippet to locate the property list:

NSString *path = [[NSBundle mainBundle] pathForResource:@“Movies” ofType:@“plist”];

Then use a combination of NSDictionary and NSArray objects to retrieve the key/value pairs stored in the property list.

Grouping items in a Table view in sections

Implement the following methods: numberOfSectionsInTab leView:tableView:numberOfRowsInSection:tableView:t itleForHeaderInSection:.

Adding an index to a Table view

Implement the sectionIndexTitlesForTableView: method.

Adding disclosure and checkmark images to a row in a Table view

Set the accessoryType property of an UITableViewCell object to one of the following:

* UITableViewCellAccessoryDetailDisclosureButton
* UITableViewCellAccessoryCheckmark
* UITableViewCellAccessoryDisclosureIndicator.

Implementing a search in a Table view

Use the Search Bar view and handle the various events in the UISearchBarDelegate protocol.

Navigating to another View window

Use the pushViewController: method of the Navigation Controller.

Android 半透明背景颜色

没有评论

2012 年 3 月 28 日 at 下午 4:35分类:Android | Development

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
      <color name="transparent_background">#50000000</color>
    </resources>

color.xml的#5000000前两位是透明的效果参数从00–99(透明–不怎么透明),后6位是颜色的设置

 

这个color.xm可以用来设定背景,或者在<shape></<shape>里

防止Mac OS X使用dhcp时修改hostname

没有评论

2012 年 3 月 26 日 at 下午 3:25分类:MacOSX

在/etc/hostconfig中增加HOSTNAME项,这样可以阻止使用dhcp时,hostname经常被更改的问题。

使用命令行的方式修改

scutil --set HostName new_hostname
sudo hostname new_hostname

或者直接编辑配置文件

tedz-mbp:~tedz$ sudo vi /etc/hostconfig
HOSTNAME=tedz

网络名修改:

1.修改网络名可以在:“系统偏好设置” -> “共享” ->“电脑名”里修改

2.也可以在终端修改:

sudo scutil --set ComputerName your_name

无觅相关文章插件,快速提升流量