当前位置:  编程技术>移动开发
本页文章导读:
    ▪ClickableSpan跟TouchableSpan        ClickableSpan和TouchableSpan: import android.text.style.UpdateAppearance; * with a movement method of LinkTouchMovementMethod, the affected spans of */     /**      */     /**     @Override } 复制代码 import android.widget.Text.........
    ▪ UINavigationController跟UITabBarController合用        UINavigationController和UITabBarController合用。 TabPage1 *firstViewControlle = [[TabPage1 alloc] init]; UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController: firstViewControlle]; UITabBarItem *time = [.........
    ▪ UI各种手势(轻拍,长按,旋转,假造,清扫,拖拽)       UI各种手势(轻拍,长按,旋转,捏合,清扫,拖拽) -(void)loadView {     self.view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 460)];     self.view.backgroundColor = [UIColor redColor];          imageV = [[U.........

[1]ClickableSpan跟TouchableSpan
    来源: 互联网  发布时间: 2014-02-18
ClickableSpan和TouchableSpan:
  •  我是这样做的,
    以下是我的ClickableSpan.java和TouchableSpan.java代码:
  • import android.text.TextPaint;
  • import android.text.style.CharacterStyle;
  • import android.text.style.UpdateAppearance;
  • import android.view.MotionEvent;
  • import android.view.View;
  • /**
  • * If an object of this type is attached to the text of a TextView
  • * with a movement method of LinkTouchMovementMethod, the affected spans of
  • * text can be selected.  If touched, the {@link #onTouch} method will
  • * be called.
  • */
  • public abstract class TouchableSpan extends CharacterStyle implements UpdateAppearance     {
  •     /**
  •      * Performs the touch action associated with this span.
  •      * @return  
  •      */
  •     public abstract boolean onTouch(View widget, MotionEvent m);
  •     /**
  •      * Could make the text underlined or change link color.
  •      */
  •     @Override
  •     public abstract void updateDrawState(TextPaint ds);
  • }
  • 复制代码

      然后,我让LinkTouchMovementMethod类继承LinkMovementMethod类;onTouchEvent()方法中,onClick变成了onTouch:
  • import android.widget.TextView;
  • public class LinkTouchMovementMethod extends LinkMovementMethod
  • {
  •     @Override
  •     public boolean onTouchEvent(TextView widget, Spannable buffer,
  •                             MotionEvent event) {
  •         int action = event.getAction();
  •         if (action == MotionEvent.ACTION_UP ||
  •             action == MotionEvent.ACTION_DOWN) {
  •             int x = (int) event.getX();
  •             int y = (int) event.getY();
  •             x -= widget.getTotalPaddingLeft();
  •             y -= widget.getTotalPaddingTop();
  •             x += widget.getScrollX();
  •             y += widget.getScrollY();
  •             Layout layout = widget.getLayout();
  •             int line = layout.getLineForVertical(y);
  •             int off = layout.getOffsetForHorizontal(line, x);
  •             TouchableSpan[] link = buffer.getSpans(off, off, TouchableSpan.class);
  •             if (link.length != 0) {
  •                 if (action == MotionEvent.ACTION_UP) {
  •                     link[0].onTouch(widget,event); //////// CHANGED HERE
  •                 } else if (action == MotionEvent.ACTION_DOWN) {
  •                     link[0].onTouch(widget,event); //////// ADDED THIS
  •                     Selection.setSelection(buffer,
  •                                            buffer.getSpanStart(link[0]),
  •                                            buffer.getSpanEnd(link[0]));
  •                 }
  •                 return true;
  •             } else {
  •                 Selection.removeSelection(buffer);
  •             }
  •         }
  •         return super.onTouchEvent(widget, buffer, event);
  •     }
  • }
  • 复制代码

    然后,在你的MovementMethod中做适当的更改:
  • TextView tv = (TextView) findViewById(R.id.tv);
  • tv.setMovementMethod(new LinkTouchMovementMethod());
  • Now to show the text:
  • touchableSpan = new TouchableSpan() {
  •     public boolean onTouch(View widget, MotionEvent m) {
  •         ...
  •     }
  •     public void updateDrawState(TextPaint ds) {
  •         ds.setUnderlineText(false);
  •         ds.setAntiAlias(true);
  •     }
  • };
  • String rv = "Text to span";
  • text = new SpannableString(rv);
  • text.setSpan(touchableSpan, begin, end, 0);
  • tv.setText(text, BufferType.SPANNABLE);
  • 复制代码


        
    [2] UINavigationController跟UITabBarController合用
        来源: 互联网  发布时间: 2014-02-18
    UINavigationController和UITabBarController合用。

    TabPage1 *firstViewControlle = [[TabPage1 alloc] init];
        UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController: firstViewControlle];
        UITabBarItem *time = [[UITabBarItem alloc] initWithTitle: @"First" image: nil tag: 0];
        time.image = [UIImage imageNamed:@""];
        nav1.tabBarItem = time;
        
        TabPage2 *secondViewController = [[TabPage2 alloc] init];
        UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController: secondViewController];
        UITabBarItem *time2 = [[UITabBarItem alloc] initWithTitle: @"second" image: nil tag: 1];
        nav2.tabBarItem = time2;
        
        UITabBarController *tabBarController = [[UITabBarController alloc] init];
        NSArray *array = [NSArray arrayWithObjects: nav1,nav2, nil];
        tabBarController.viewControllers = array;
        
        [self presentViewController:tabBarController animated:YES completion:nil];
    
    
    
    ///////////在TabPage1中
    self.navigationitem.title = @"111";
    



        
    [3] UI各种手势(轻拍,长按,旋转,假造,清扫,拖拽)
        来源: 互联网  发布时间: 2014-02-18
    UI各种手势(轻拍,长按,旋转,捏合,清扫,拖拽)

    -(void)loadView

    {

        self.view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 460)];

        self.view.backgroundColor = [UIColor redColor];

        

        imageV = [[UIImageView alloc]initWithFrame:CGRectMake(70, 150, 200, 200)];

        

        imageV.backgroundColor = [UIColor blueColor];

        

        [self.view addSubview:imageV];

        

        [imageV release];

        

        NSArray *arr = [NSArray arrayWithObjects:@"轻拍",@"长按",@"旋转",@"捏合",@"轻扫",@"拖拽", nil];

        

        UISegmentedControl *seg = [[UISegmentedControl alloc]initWithItems:arr];

        

        [seg addTarget:self action:@selector(tap:) forControlEvents:UIControlEventValueChanged];

        

        seg.frame = CGRectMake(0, 400, 320, 40);

        

        imageV.userInteractionEnabled = YES;

        

        [self.view addSubview:seg];

        

        

    }

    -(void)tap:(UISegmentedControl *)tap

    {

       for(id gesture in imageV.gestureRecognizers)

       {

           [imageV removeGestureRecognizer:gesture];

       }

        

        switch (tap.selectedSegmentIndex)

        {

            case 0:

            {

                UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dotap:)];

                

                [imageV addGestureRecognizer:tap];

                

                imageV.userInteractionEnabled = YES;

                

                [tap release];

                

                break;

            }

                case 1:

            {

                UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)];

                

                [imageV addGestureRecognizer:longPress];

                

                [longPress release];

                

                break;

            }

                case 2:

            {

                UIRotationGestureRecognizer *rotationPress = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationPress:)];

                

                [imageV addGestureRecognizer:rotationPress];

                

                [rotationPress release];

                break;

            }

               case 3:

            {

                UIPinchGestureRecognizer *pinchPress = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchPress:)];

                [imageV addGestureRecognizer:pinchPress];

                

                [pinchPress release];

                break;

            }

                case 4:

            {

                UISwipeGestureRecognizer *swipePress = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipePress:)];

                [imageV addGestureRecognizer:swipePress];

                [swipePress release];


                

                

                UISwipeGestureRecognizer *swipePress1 = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipePress:)];

                [imageV addGestureRecognizer:swipePress1];

                swipePress.direction = UISwipeGestureRecognizerDirectionLeft  ;

                

                [swipePress1 release];

                break;

                

                        }

                case 5:

            {

                UIPanGestureRecognizer *panPress = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panPress:)];

                

                [imageV addGestureRecognizer:panPress];

                

                [panPress release];

                break;

            }

            default:

                break;

        }

    }

    -(void)dotap:(UITapGestureRecognizer *)dotap//轻按随机换图

    {

        NSString *imageName = [NSString stringWithFormat:@"h%d.jpeg",arc4random()%8+1];

        

        imageV.image = [UIImage imageNamed:imageName];

    }

    -(void)longPress:(UILongPressGestureRecognizer *)longPress//长按按顺序换图

    {

       

        if(longPress.state == UIGestureRecognizerStateEnded)

        {

           

            


           NSString *imageName = [NSString stringWithFormat:@"h%d.jpeg",i%8+1] ;

        

        imageV.image = [UIImage imageNamed:imageName];

            

            i = i+1;

        }

        

    }

    -(void)rotationPress:(UIRotationGestureRecognizer *)rotationPress//旋转

    {

        [imageV setTransform:CGAffineTransformMakeRotation(rotationPress.rotation)];  

    }


    -(void)pinchPress:(UIPinchGestureRecognizer *)pinchPress//捏合

    {

        [imageV setTransform:CGAffineTransformMakeScale(pinchPress.scale, pinchPress.scale)];

    }


    -(void)swipePress:(UISwipeGestureRecognizer *)swipePress//轻扫

    {

        [UIView beginAnimations:nil context:nil];

        

        [UIView setAnimationTransition:(swipePress.direction == UISwipeGestureRecognizerDirectionLeft )?UIViewAnimationTransitionFlipFromLeft:UIViewAnimationTransitionFlipFromRight forView:imageV cache:YES];

        

        

           [UIView commitAnimations];

    }

    -(void)panPress:(UIPanGestureRecognizer *)panPress //拖拽

    {

        CGPoint point =[panPress translationInView:imageV];

        

        imageV.transform = CGAffineTransformMakeTranslation(point.x, point.y);

    }



        
    最新技术文章:
    ▪Android开发之登录验证实例教程
    ▪Android开发之注册登录方法示例
    ▪Android获取手机SIM卡运营商信息的方法
    ▪Android实现将已发送的短信写入短信数据库的...
    ▪Android发送短信功能代码
    ▪Android根据电话号码获得联系人头像实例代码
    ▪Android中GPS定位的用法实例
    ▪Android实现退出时关闭所有Activity的方法
    ▪Android实现文件的分割和组装
    ▪Android录音应用实例教程
    ▪Android双击返回键退出程序的实现方法
    ▪Android实现侦听电池状态显示、电量及充电动...
    ▪Android获取当前已连接的wifi信号强度的方法
    ▪Android实现动态显示或隐藏密码输入框的内容
    ▪根据USER-AGENT判断手机类型并跳转到相应的app...
    ▪Android Touch事件分发过程详解
    ▪Android中实现为TextView添加多个可点击的文本
    ▪Android程序设计之AIDL实例详解
    ▪Android显式启动与隐式启动Activity的区别介绍
    ▪Android按钮单击事件的四种常用写法总结
    ▪Android消息处理机制Looper和Handler详解
    ▪Android实现Back功能代码片段总结
    ▪Android实用的代码片段 常用代码总结
    ▪Android实现弹出键盘的方法
    ▪Android中通过view方式获取当前Activity的屏幕截...
    ▪Android提高之自定义Menu(TabMenu)实现方法
    ▪Android提高之多方向抽屉实现方法
    ▪Android提高之MediaPlayer播放网络音频的实现方法...
    ▪Android提高之MediaPlayer播放网络视频的实现方法...
    ▪Android提高之手游转电视游戏的模拟操控
     


    站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3