如果不使用CPLD或者FPGA作为地址译码器,那么74LS138芯片会是一个很好的选择。74LS138的A、B、C产生8位
低电平有效的输出Y0-Y7,每个输出连接到存储器的CS端。S3、S2接地,S1=1时候选中74LS138芯片。
请看图,计算Y4所控制的地址范围。
首先:A19 A18 A17 A16 A15 A14
1 1 1 1 0 0
这样才能选中芯片并且选中芯片的Y4引脚。
A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1
即是全1或者全0的时候。那么Y4的地址范围是:F0000H到F3FFFH。
注意:A19、A18、A17必须是1来激活译码器。
之前做了个弱提示的UI,看了下文件创建时间,竟然过去快3个月了。
这个功能的部分要求如下:
- 出现的方式由小到大,消失的方式由大到小,center不变。
- 支持短文案、长文案提示。只有文案提示的情况下,定时自动消失,hideOnTimer。
- 支持纯loading、文案和loading结合。展示loading菊花的情况下,由调用方根据条件,显式地调用hide方法。
部分效果如下:
出现和消失的动画代码如下:
/* 出现动画 */ CATransform3D transform = CATransform3DMakeScale(0.001, 0.001, 1.0); hintView.layer.transform = transform; hintView.alpha = 0; transform = CATransform3DMakeScale(1.0, 1.0, 1.0); [UIView beginAnimations:nilcontext:nil]; [UIView setAnimationDuration:0.5]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; hintView.layer.transform = transform; hintView.alpha = 1; [UIView commitAnimations]; /* 消失动画 */ CATransform3D transform = CATransform3DMakeScale(0.001, 0.001, 0.001); [UIView beginAnimations:nilcontext:nil]; [UIView setAnimationDelay:0.0]; [UIView setAnimationDuration:.5]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; hintView.layer.transform = transform; hintView.alpha = 0; [UIView commitAnimations];
其中,对于纯文案弱提示的自动消失,采用的是NSTimer定时机制(如果采用dispatch_after呢?):
[NSTimer scheduledTimerWithTimeInterval:DEFAULT_SHOW_TIME target:sharedHintView selector:@selector(hideOnTimer:) userInfo:nil repeats:NO];一切都工作得好好的,直到有一天浮出弱提示时,一直滚动UITableView,弱提示不会自动消失⋯⋯
这时候,第一感觉是由于界面一直在滚动,UI事件不停,所以NSTimer得不到激发。
如果是这样的话,那么UI事件的优先级就高于NSTimer事件优先级,每次NSRunLoop处理事件,都先处理UI事件,再处理NSTimer事件。在事件队列里,UI事件都根据优先级插到NSTimer事件前面。
而且,这样得要求NSRunLoop每次进入while循环都只处理一个事件!否则即使在连续UI事件产生的情况下,也无法保证NSTimer事件始终得不到处理。这不科学!这样不仅会阻碍NSTimer事件,还会阻碍很多其它事件。
合理的while循环应该类似下面的伪代码(假设UI事件先于NSTimer事件得到处理):
while ( getEvents() ) {
for ( event in UIEvents ) {
processUIEvent(event);
}
for ( event in TimerEvents ) {
processTimerEvent(event);
}
}所以,第一感觉有问题。于是我打开Google,敲入“nstimer not fire”,然后在Google Suggest中选择条目。
StackOverflow上的这个回答从代码上解决了我遇到的问题,并且和这个问题一起为我解答了疑惑。
当我们调用scheduledTimerWithTimeInterval方法,会创建一个NSTimer对象,把它交给当前runloop以默认mode来调度。
相当于执行如下代码:
[currentRunLoop addTimer:timer forMode:defaultMode];
我们可以想到,runloop中维护了一张map,以mode为key,以某种结构为value,不妨命名为NSRunLoopState。
这个NSRunLoopState结构中,需要维护input sources集合以及NSTimer等事件源。
而当我们滚动UITableView/UIScrollView,或者做一些其它UI动作时,当前runloop的mode会切换到UITrackingRunLoopMode,这是由日志输出得到的:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
NSLog(@"Current RunLoop Mode is %@\n", [[NSRunLoop currentRunLoop] currentMode]);
}这就相当于执行如下代码:
[currentRunLoop runMode:UITrackingRunLoopMode beforeDate:date];
这个时候,我们需要根据UITrackingRunLoopMode来获取相应的NSRunLoopState结构,并对结构中维护的事件源进行处理。
所以,添加到defaultMode的NSTimer在发生UI滚动时,不会得到处理。
--------------------------------------------------
原文地址:http://blog.csdn.net/jasonblog/article/details/7854693
Jason Lee @ Hangzhou
2012.08.11
在很多APP中,我们都可以看见那些特效绚丽的滑动选项条,那么如何才能够简单,快速的实现那样的效果呢?首先我们分析一下那样的控件都需要什么?
1、既然是选项条,必然需要选择,因此我们需要UIButton。
2、选择那个button,那个button的背景从之前选择的那个平滑的移动到当前选择的button上,因此我们不能单纯的使用button的背景色,我们需要一个转为提供颜色的view,这样才有可能达到视图的平滑移动。
3、我们这些view需要一个载体,进行同意管理,因此我们需要一个MainView,来承载这些控件。
好了,分析完了,我们动手吧。
第一步:我们需要定义一些我们需要的对象,某些变量需要全局使用,定义的时候根据需要在权衡。
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController{
NSMutableArray *btnArray;
NSMutableArray *titleArray;
}
@property (nonatomic,strong) UIView *customView;
@property (nonatomic,strong) UIView *backView;
@property (nonatomic,strong) UIButton *myButton;
-(void)myButtonClcik:(id)sender;
@end第二步:在我们的额viewdidload方法中,或者自定义一个方法中创建我么的界面元素。《这里我引日了QuartzCore框架,是为了使用其layer属性》
#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>
@interface ViewController ()
@end
@implementation ViewController
@synthesize customView;
@synthesize backView;
@synthesize myButton;
//每行显示的button个数
#define kSelectNum 6
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//创建背景视图,并设置背景颜色或者图片
customView = [[UIView alloc]initWithFrame:CGRectMake(20, 100, 900, 60)];
customView.backgroundColor = [UIColor blackColor];
//设置customView的样式,变为圆角
customView.layer.cornerRadius = 15.0f;
customView.layer.masksToBounds = YES;
//将customView add 到当前主View中
[self.view addSubview:customView];
//创建button的背景视图
backView = [[UIView alloc] initWithFrame:CGRectMake(5, 5, 95, 50)];
backView.backgroundColor = [UIColor blueColor];
//设置为圆角。以免造成重叠显示
backView.layer.cornerRadius = 15.0f;
backView.layer.masksToBounds = YES;
//将backView视图add到customView中
[customView addSubview:backView];
//创建button,首先button的个数是不固定的,因此我们需要动态的生成button
//创建数组,保存button的title
btnArray = [[NSMutableArray alloc]init];
titleArray = [[NSMutableArray alloc]initWithObjects:@"热播大片",@"最新更新",@"最热观看",@"美剧大片",@"韩剧频道",@"综艺娱乐", nil];
//动态生成button
for (int i = 0; i < kSelectNum; i ++){
myButton = [UIButton buttonWithType:UIButtonTypeCustom];
myButton.titleLabel.font = [UIFont boldSystemFontOfSize:20.0f];
[myButton setTitle:[titleArray objectAtIndex:i] forState:UIControlStateNormal];
[myButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
[myButton setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
[myButton setFrame:CGRectMake(i%(kSelectNum + 1)*140+5, 5, 95, 50)];
[myButton addTarget:self action:@selector(myButtonClcik:) forControlEvents:UIControlEventTouchUpInside];
myButton.tag = i;
[btnArray addObject:myButton];
[customView addSubview:myButton];
//设置默认选择的button.title的颜色
if(i == 0){
myButton.selected = YES;
}
}
}
第三步:我们为button添加按钮点击事件,同时设置背景色滑动特效。
- (void)myButtonClcik:(id)sender{
// NSString *selectedBtn = [NSString stringWithFormat:@"%@",[titleArray objectAtIndex:button.tag]];
// UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:selectedBtn delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
// [alert show];
//添加动画过度效果
[UIView beginAnimations:@"slowGlide" context:nil];
[UIView setAnimationDuration:0.3f];
//设置每次只能选择一个button
UIButton *button = (UIButton *)sender;
if(!button.selected){
for (UIButton *eachBtn in btnArray) {
if(eachBtn.isSelected){
[eachBtn setSelected:NO];
}
}
[button setSelected:YES];
//设置点击那个按钮,那个按钮的背景改变为backView的颜色
[backView setFrame:button.frame];
}
[UIView commitAnimations];
}
最后成型,我们就可以根据我们的样式需要进行调整了。
此种方法简单,但是可能有些地方不合理,望高手指点。
demo 下载地址:http://download.csdn.net/detail/zyc851224/4492735