当前位置: 编程技术>移动开发
本页文章导读:
▪怎么解决UIScrollView中添加UITapGestureRecognizer跟UIButton点击事件冲突 如何解决UIScrollView中添加UITapGestureRecognizer跟UIButton点击事件冲突1.添加单击事件
UITapGestureRecognizer *gensture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(scrollViewTapAction)];
gensture.delegate .........
▪ ViewPager的使用方法跟实现过程 ViewPager的使用方法和实现过程看图先:
页面中填充内容是随机关键词飞入和飞出动画效果,随后会更新,现在请先无视吧
首先是 导入jar包 下载地址: android-support-v4.jar
布.........
▪ Core Data浅谈系列之4 : 数据模型的版本变迁 Core Data浅谈系列之四 : 数据模型的版本变迁继上一篇文章末尾提到的,一支队伍可以添加多名球员,不过一名球员只能属于一支队伍中,这分别对应着Core Data中一对多和一对一的属性关系:.........
[1]怎么解决UIScrollView中添加UITapGestureRecognizer跟UIButton点击事件冲突
来源: 互联网 发布时间: 2014-02-18
如何解决UIScrollView中添加UITapGestureRecognizer跟UIButton点击事件冲突
1.添加单击事件
UITapGestureRecognizer *gensture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(scrollViewTapAction)]; gensture.delegate = self; [scrollView addGestureRecognizer:gensture]; [gensture release];
2.实现UIGestureRecognizerDelegate中的
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { UIView *view = [touch view]; if ([view isKindOfClass:[UIButton class]]) { return NO; } return YES; }
[2] ViewPager的使用方法跟实现过程
来源: 互联网 发布时间: 2014-02-18
ViewPager的使用方法和实现过程
看图先:
页面中填充内容是随机关键词飞入和飞出动画效果,随后会更新,现在请先无视吧
首先是 导入jar包 下载地址: android-support-v4.jar
布局文件里添加viewPager布局
<android.support.v4.view.ViewPager android:id="@+id/search_viewpager" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" > </android.support.v4.view.ViewPager>
然后就是Activity了,主要写了左右滑动切换页面,还有一个小图片随页面切换 位移的动画效果
public class SearchAllcityActivity extends Activity { private KeywordsFlow keywordsFlow; private ViewPager viewPager; private ImageView imageView; private List<View> lists = new ArrayList<View>(); private ViewPagerAdapter adapter; private Bitmap cursor; private int offSet; private int currentItem; private Matrix matrix = new Matrix(); private int bmWidth; private Animation animation; private Button shuaxin_sq, shuaxin_fl; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.search_allcity); // 随页面滑动图片 imageView = (ImageView) findViewById(R.id.viewpaget_img); // 热门商圈和热门分类 页面添加到viewPager集合 lists.add(getLayoutInflater().inflate(R.layout.search_hot_shangqu, null)); lists.add(getLayoutInflater().inflate(R.layout.search_hot_fenlei, null)); // 初始化滑动图片位置 initeCursor(); adapter = new ViewPagerAdapter(lists); viewPager = (ViewPager) findViewById(R.id.search_viewpager); viewPager.setAdapter(adapter); // ViewPager滑动监听器 viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageSelected(int arg0) { // TODO Auto-generated method stub // 当滑动时,顶部的imageView是通过animation缓慢的滑动 switch (arg0) { case 0: if (currentItem == 1) { animation = new TranslateAnimation(offSet * 2 + bmWidth, 0, 0,0); } else if (currentItem == 2) { animation = new TranslateAnimation(offSet * 4 + 2 * bmWidth, 0,0, 0); } break; case 1: if (currentItem == 0) { animation = new TranslateAnimation(0, offSet * 2 + bmWidth, 0,0); } else if (currentItem == 2) { animation = new TranslateAnimation(4 * offSet + 2 * bmWidth,offSet * 2 + bmWidth, 0, 0); } break; } currentItem = arg0; animation.setDuration(500); animation.setFillAfter(true); imageView.startAnimation(animation); } @Override public void onPageScrolled(int arg0, float arg1, int arg2) { // TODO Auto-generated method stub } @Override public void onPageScrollStateChanged(int arg0) { // TODO Auto-generated method stub } }); } /** * 计算滑动的图片的位置 */ private void initeCursor() { cursor = BitmapFactory.decodeResource(getResources(),R.drawable.viewpager_img); bmWidth = cursor.getWidth(); DisplayMetrics dm; dm = getResources().getDisplayMetrics(); offSet = (dm.widthPixels - 2 * bmWidth) / 4; matrix.setTranslate(offSet, 0); imageView.setImageMatrix(matrix); // 需要iamgeView的scaleType为matrix currentItem = 0; } }
最后,不能忘了ViewPager的Adapter
public class ViewPagerAdapter extends PagerAdapter{ List<View> viewLists; public ViewPagerAdapter(List<View> lists) { viewLists = lists; } @Override public int getCount() { //获得size // TODO Auto-generated method stub return viewLists.size(); } @Override public boolean isViewFromObject(View arg0, Object arg1) { // TODO Auto-generated method stub return arg0 == arg1; } @Override public void destroyItem(View view, int position, Object object) //销毁Item { ((ViewPager) view).removeView(viewLists.get(position)); } @Override public Object instantiateItem(View view, int position) //实例化Item { ((ViewPager) view).addView(viewLists.get(position), 0); return viewLists.get(position); } }
[3] Core Data浅谈系列之4 : 数据模型的版本变迁
来源: 互联网 发布时间: 2014-02-18
Core Data浅谈系列之四 : 数据模型的版本变迁
继上一篇文章末尾提到的,一支队伍可以添加多名球员,不过一名球员只能属于一支队伍中,这分别对应着Core Data中一对多和一对一的属性关系:
如上两图,是在Team实体里面添加了一个players关系,指向Player实体,可以一支球队关联多名球员,并且最多只允许关联15名球员。
同样地,也为Player实体添加team关系,指向Team实体:
一名球员只能关联一支球队,并且让这个关系成双向的,即一个Player对象属于某支球队时,该球队的players属性就自动关联该Player对象。
做完以上对表关系的修改,再次运行程序。
Oops,运行不起来——
2013-01-16 16:56:18.667 cdNBA[18591:c07] Error : The operation couldn’t be completed. (Cocoa error 134100.) 2013-01-16 16:56:18.670 cdNBA[18591:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'This NSPersistentStoreCoordinator has no persistent stores. It cannot perform a save operation.'
这是由于我们刚才做了一番修改,persistentStoreCoordinator无法适应新的数据模型。
当开启一个新版本时,如果数据模型发生变动,我们需要创建一个新版本使用的数据模型:
并将其设置为当前版本使用的数据模型:
So,我们刚才发生的变动都应该应用在cdNBA 2.xcdatamodel上。
除此之外,还需要在persistentStoreCoordinator添加存储文件时设置一个选项:
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator { if (nil != _persistentStoreCoordinator) { return_persistentStoreCoordinator; } NSString *storeType = NSSQLiteStoreType; NSString *storeName = @"cdNBA.sqlite"; NSError *error = NULL; NSURL *storeURL = [NSURLfileURLWithPath:[[selfapplicationDocumentsDirectory] stringByAppendingPathComponent:storeName]]; NSDictionary *options = [NSDictionarydictionaryWithObjectsAndKeys: [NSNumbernumberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumbernumberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil]; _persistentStoreCoordinator = [[NSPersistentStoreCoordinatoralloc] initWithManagedObjectModel:self.managedObjectModel]; if (![_persistentStoreCoordinator addPersistentStoreWithType:storeType configuration:nilURL:storeURL options:options error:&error]) { NSLog(@"Error : %@\n", [error localizedDescription]); NSAssert1(YES, @"Failed to create store %@ with NSSQLiteStoreType", [storeURL path]); } return _persistentStoreCoordinator; }
做完上面的工作,再跑一遍Demo。
Brief Talk About Core Data Series, Part 4 : Versioning of The Data Model
Jason Lee @ Hangzhou
Blog : http://blog.csdn.net/jasonblog
Weibo : http://weibo.com/jasonmblog
最新技术文章: